Spring Boot

Spring Bootベースの単純なWebアプリケーション

始める前に

インストールの手順に従って、Verrazzanoをインストールします。

ノート: Spring Bootサンプル・アプリケーションのデプロイメント・ファイルは、<VERRAZZANO_HOME>/examples/springboot-appにあるVerrazzanoプロジェクトに含まれています(VERRAZZANO_HOMEは、Verrazzanoプロジェクトのルートです)。

Spring Bootアプリケーションのデプロイ

この例では、Spring Bootを使用して開発された単純なWebアプリケーションを示します。このアプリケーションの詳細およびソース・コードについては、Verrazzanoの例を参照してください。

  1. Spring Bootアプリケーションのネームスペースを作成し、ネームスペースがVerrazzanoによって管理されることを示すラベルを追加します。

    $ kubectl create namespace springboot
    $ kubectl label namespace springboot verrazzano-managed=true istio-injection=enabled
    
  2. アプリケーションをデプロイするには、Spring Boot OAMリソースを適用します。

    $ kubectl apply -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.1.2/examples/springboot-app/springboot-comp.yaml
    $ kubectl apply -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.1.2/examples/springboot-app/springboot-app.yaml
    
  3. Spring Bootアプリケーションの準備が完了するのを待ちます。

    $ kubectl wait \
       --for=condition=Ready pods \
       --all \
       -n springboot \
       --timeout=300s
    

アプリケーションの探索

  1. アプリケーション用に生成されたホスト名を取得します。

    $ HOST=$(kubectl get gateways.networking.istio.io \
         -n springboot \
         -o jsonpath={.items[0].spec.servers[0].hosts[0]})
    $ echo $HOST
    
    # Sample output
    springboot-appconf.springboot.11.22.33.44.nip.io
    
  2. istio-ingressgatewayサービスのEXTERNAL_IPアドレスを取得します。

    $ ADDRESS=$(kubectl get service \
         -n istio-system istio-ingressgateway \
         -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    $ echo $ADDRESS
    
    # Sample output
    11.22.33.44
    
  3. アプリケーションにアクセスします:

    • コマンドラインの使用

      # The expected response of this query is the HTML of a web page
      $ curl -sk \
          https://${HOST} \
          --resolve ${HOST}:443:${ADDRESS}
      
      $ curl -sk \
          https://${HOST}/facts \
          --resolve ${HOST}:443:${ADDRESS}
      
      # Sample output
      In 1524, Verrazzano became the first European to enter the New York Harbor and the Hudson River.
      

      nip.ioを使用している場合は、--resolveを含める必要はありません。

    • ブラウザによるローカル・テスト

      一時的に、/etc/hostsファイル(MacまたはLinuxの場合)またはc:\Windows\System32\Drivers\etc\hostsファイル(Windows 10の場合)を変更して、ホスト名をイングレス・ゲートウェイのEXTERNAL-IPアドレスにマップするエントリを追加します。たとえば:

      11.22.33.44 springboot.example.com
      

      その後、ブラウザでhttps://springboot.example.com/およびhttps://springboot.example.com/factsからアプリケーションにアクセスできます。

      nip.ioを使用している場合は、HOST変数(https://${HOST}/factsなど)を使用してブラウザでアプリケーションにアクセスできます。プロキシを使用する場合は、*.nip.ioNO_PROXYリストに追加する必要がある場合があります。

    • 独自のDNS名の使用

      • 独自のDNS名をイングレス・ゲートウェイのEXTERNAL-IPアドレスにポイントします。

      • この場合、Spring Bootアプリケーションをデプロイする前に、springboot-app.yamlファイルを編集してhostsセクション(yourhost.your.domainなど)で適切な値を使用する必要があります。

      • その後、ブラウザを使用して、https://<yourhost.your.domain>/およびhttps://<yourhost.your.domain>/factsでアプリケーションにアクセスできます。

        アクチュエータ・エンドポイントはパス/actuatorでアクセスでき、Prometheusサーバーによってスクレイプ可能な形式でメトリック・データを公開するPrometheusエンドポイントはパス/actuator/prometheusでアクセスできます。

  4. デプロイされたアプリケーションに関連付けられた様々なエンドポイントを使用して、ログやメトリックなどをさらに探索できます。ここの指示に従ってアクセスできます。

アプリケーションのアンデプロイ

  1. アプリケーションをアンデプロイするには、Spring Boot OAMリソースを削除します。

    $ kubectl delete -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.1.2/examples/springboot-app/springboot-app.yaml
    $ kubectl delete -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.1.2/examples/springboot-app/springboot-comp.yaml
    
  2. アプリケーション・ポッドの終了後にネームスペースspringbootを削除します。

    $ kubectl delete namespace springboot