【GCP】Qwiklabs の「GCP の基礎」を勉強しています~Google Cloud の基礎: チャレンジラボ~

Google Cloud の基礎: チャレンジラボ GCP
Google Cloud の基礎: チャレンジラボ

Qwiklabs の「GCP の基礎」を進めていきたいと思います。

Google Cloud の基礎: チャレンジラボ

概要

「GCP の基礎」で学んだことをもう一度確認します。

コマンド

プロジェクトの jumphost インスタンスを作成する

gcloud compute project-info describe --project <GCPプロジェクトID>

GCPプロジェクトの設定を確認します。

  - key: google-compute-default-zone
    value: us-east1-b
  - key: google-compute-default-region
    value: us-east1

ゾーンとリージョンは上記の想定で進めていきます。

export ZONE=us-east1-b
export REGION=us-east1
echo $ZONE
echo $REGION
gcloud compute instances create nucleus-jumphost --machine-type f1-micro --zone $ZONE

Kubernetes クラスタを作成する

gcloud config set compute/zone $ZONE
gcloud config set compute/region $REGION
gcloud container clusters create my-cluster
gcloud container clusters get-credentials my-cluster
kubectl create deployment hello-app --image=gcr.io/google-samples/hello-app:2.0
kubectl expose deployment hello-app --type=LoadBalancer --port 8080
kubectl get service

ブラウザでページが表示されることを確認します。
http://<外部IPアドレス>:8080

HTTP ロードバランサの背後にウェブサイトを作成する

cat << EOF > startup.sh
#! /bin/bash
apt-get update
apt-get install -y nginx
service nginx start
sed -i -- 's/nginx/Google Cloud Platform - '"\$HOSTNAME"'/' /var/www/html/index.nginx-debian.html
EOF

すべての仮想マシンインスタンスで使用される起動スクリプトを作成します。

gcloud compute instance-templates create nginx-template --metadata-from-file startup-script=startup.sh
gcloud compute target-pools create nginx-pool
gcloud compute instance-groups managed create nginx-group --base-instance-name nginx --size 2 --template nginx-template --target-pool nginx-pool
gcloud compute instances list
gcloud compute firewall-rules create www-firewall --allow tcp:80

VMインスタンスの外部IPアドレスでページが表示されることを確認します。
http://<外部IPアドレス>

gcloud compute http-health-checks create http-basic-check
gcloud compute instance-groups managed set-named-ports nginx-group --named-ports http:80
gcloud compute backend-services create nginx-backend --protocol HTTP --http-health-checks http-basic-check --global
gcloud compute backend-services add-backend nginx-backend --instance-group nginx-group --instance-group-zone $ZONE --global
gcloud compute url-maps create web-map --default-service nginx-backend
gcloud compute target-http-proxies create http-lb-proxy --url-map web-map
gcloud compute forwarding-rules create http-content-rule --global --target-http-proxy http-lb-proxy --ports 80
gcloud compute forwarding-rules list

転送ルールの http-content-rule の IPアドレスに接続します。
http://<http-content-ruleのIPアドレス>

まとめ

最後の転送ルールの反映に時間がかかるようです。
気長に待ちましょう。

https://www.papacoder.net/gcp-training-free-campaign/

コメント

タイトルとURLをコピーしました