このチュートリアルは、ウェブ アプリケーションを Google Kubernetes Engine(GKE)クラスタにデプロイし、HTTPS ロードバランサで公開することに関心があるクラウド アーキテクトと運用管理者を対象としています。
目標
このチュートリアルの学習内容は次のとおりです。
- GKE クラスタを作成する。
- Terraform を使用してグローバル IP アドレスと Cloud DNS ゾーンを作成する。
- HTTPS ロード バランシングを構成する。
- サンプルのウェブ アプリケーションをデプロイする。
費用
このドキュメントでは、課金対象である次の Google Cloudコンポーネントを使用します。
料金計算ツールを使うと、予想使用量に基づいて費用の見積もりを生成できます。
このドキュメントに記載されているタスクの完了後、作成したリソースを削除すると、それ以上の請求は発生しません。詳細については、クリーンアップをご覧ください。
始める前に
プロジェクトを設定する
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
Roles required to create a project
To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. -
Verify that billing is enabled for your Google Cloud project.
-
Enable the Google Kubernetes Engine, Cloud DNS APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
Roles required to create a project
To create a project, you need the Project Creator role (
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles. -
Verify that billing is enabled for your Google Cloud project.
-
Enable the Google Kubernetes Engine, Cloud DNS APIs.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. - ドメイン名を所有している必要があります。ドメイン名は 63 文字以下にする必要があります。Google Domains または他の登録事業者を使用できます。
環境変数を設定します。
PROJECT_ID=$(gcloud config get-value project) gcloud config set project $PROJECT_ID gcloud config set compute/region us-central1コード リポジトリのクローンを作成します。
git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples.git作業ディレクトリを変更します。
cd kubernetes-engine-samples/autopilot/networking-tutorialTerraform を初期化します。
terraform initインフラストラクチャの変更を表示します。
terraform planプロンプトが表示されたら、ドメインを入力します(
my-domain.netなど)。Terraform 構成を適用します。
terraform apply --auto-approveプロンプトが表示されたら、ドメインを入力します(
my-domain.netなど)。出力は次のようになります。
Apply complete! Resources: 1 added, 0 changed, 0 destroyed. Outputs: cluster_name = "networking-cluster" region = "us-central1"次のマニフェストには、ManagedCertificate、FrontendConfig、Deployment、Service、Ingress が記述されています。
DOMAIN_NAMEはmy-domain.netなどのドメイン名に置き換えます。このマニフェストには次のプロパティがあります。
networking.gke.io/managed-certificates: ManagedCertificate の名前。networking.gke.io/v1beta1.FrontendConfig: FrontendConfig リソースの名前。kubernetes.io/ingress.global-static-ip-name: IP アドレスの名前。kubernetes.io/ingress.class: 外部アプリケーション ロードバランサを作成するように GKE Ingress コントローラに指示します。
マニフェストをクラスタに適用します。
kubectl apply -f kubernetes-manifests.yamlIngress が作成されたことを確認します。
kubectl describe ingress frontend出力は次のようになります。
... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ADD 2m loadbalancer-controller default/frontend Normal CREATE 1m loadbalancer-controller ip: 203.0.113.2 ...Ingress のプロビジョニングには数分かかる場合があります。
SSL 証明書のステータスを確認します。
kubectl get managedcertificates.networking.gke.io networking-managed-certSSL 証明書のプロビジョニングには最長で 30 分ほどかかる場合があります。次の出力は、SSL 証明書の準備ができていることを示しています。
NAME AGE STATUS networking-managed-cert 28m Activecurlコマンドを実行します。curl -Lv https://DOMAIN_NAME出力は次のようになります。
* Trying 34.160.115.33:443... * Connected to DOMAIN_NAME (34.160.115.33) port 443 (#0) ... * TLSv1.3 (IN), TLS handshake, Certificate (11): ... * Server certificate: * subject: CN=DOMAIN_NAME ... > Host: DOMAIN_NAME- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
Kubernetes リソースを削除します。
kubectl delete -f kubernetes-manifests.yamlTerraform リソースを削除します。
terraform destroy --auto-approveプロンプトが表示されたら、ドメインを入力します(
my-domain.netなど)。- GKE ネットワーキングの詳細を確認する。
環境の設定
このチュートリアルでは、Cloud Shell を使用してGoogle Cloudでホストされているリソースを管理します。Cloud Shell には、このチュートリアルに必要な、Terraform、kubectl、gcloud CLI などのソフトウェアがプリインストールされています。
GKE クラスタを作成する
次の Terraform ファイルによって GKE クラスタが作成されます。
次の Terraform ファイルによってグローバル IP アドレスと Cloud DNS ゾーンが作成されます。
外部アプリケーション ロードバランサを作成する
アプリケーションをテストする
クリーンアップ
このチュートリアルで使用したリソースについて、Google Cloud アカウントに課金されないようにするには、リソースを含むプロジェクトを削除するか、プロジェクトを維持して個々のリソースを削除します。