Spring Boot
始める前に
インストールの手順に従って、Verrazzanoをインストールします。
ノート: Spring Bootサンプル・アプリケーションのデプロイメント・ファイルは、<VERRAZZANO_HOME>/examples/springboot-app
にあるVerrazzanoプロジェクトに含まれています(VERRAZZANO_HOME
は、Verrazzanoプロジェクトのルートです)。
Spring Bootアプリケーションのデプロイ
この例では、Spring Bootを使用して開発された単純なWebアプリケーションを示します。このアプリケーションの詳細およびソース・コードについては、Verrazzanoの例を参照してください。
ノート
このアプリケーションをデフォルトのネームスペースで実行するには:
$kubectl label namespace default verrazzano-managed=true istio-injection=enabled
デフォルトのネームスペースを選択した場合は、ステップ1をスキップして、残りのコマンドの-n
オプションを無視できます。
-
Spring Bootアプリケーションのネームスペースを作成し、ネームスペースがVerrazzanoによって管理されることを示すラベルを追加します。
$ kubectl create namespace springboot $ kubectl label namespace springboot verrazzano-managed=true istio-injection=enabled
-
アプリケーションをデプロイするには、Spring Boot OAMリソースを適用します。
$ kubectl apply -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.2.2/examples/springboot-app/springboot-comp.yaml -n springboot $ kubectl apply -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.2.2/examples/springboot-app/springboot-app.yaml -n springboot
-
Spring Bootアプリケーションの準備が完了するのを待ちます。
$ kubectl wait \ --for=condition=Ready pods \ --all \ -n springboot \ --timeout=300s
アプリケーションの探索
-
アプリケーション用に生成されたホスト名を取得します。
$ 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
-
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
-
アプリケーションにアクセスします:
-
コマンドラインの使用
# 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.io
をNO_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
でアクセスできます。
-
-
-
デプロイされたアプリケーションに関連付けられた様々なエンドポイントを使用して、ログやメトリックなどをさらに探索できます。ここの指示に従ってアクセスできます。
アプリケーションのアンデプロイ
-
アプリケーションをアンデプロイするには、Spring Boot OAMリソースを削除します。
$ kubectl delete -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.2.2/examples/springboot-app/springboot-app.yaml -n springboot $ kubectl delete -f https://raw.githubusercontent.com/verrazzano/verrazzano/v1.2.2/examples/springboot-app/springboot-comp.yaml -n springboot
-
アプリケーション・ポッドの終了後にネームスペース
springboot
を削除します。$ kubectl delete namespace springboot