https://cloud.google.com/load-balancing/docs/network/setting-up-network
https://www.topgate.co.jp/google-cloud-load-balancer
レイヤ 4 負荷分散
外部IPアドレス
|
転送ルール
|
ターゲットプール ━ ヘルスチェック
|
バックエンドインスタンス
-- 1. 前作業
gcloud init
gcloud auth list
gcloud --version
gcloud projects create project01-9999999 \
--name="project01"
gcloud config list
gcloud config set project project01-9999999
gcloud config set compute/region asia-northeast1
gcloud config set compute/zone asia-northeast1-a
gcloud beta billing accounts list
gcloud beta billing projects link project01-9999999 --billing-account=111111-111111-111111
gcloud services enable compute.googleapis.com --project project01-9999999
-- 2. バックエンド インスタンスの設定
gcloud compute instances create vm01 \
--image-family debian-10 \
--image-project debian-cloud \
--machine-type=n1-standard-1 \
--network-interface=network-tier=STANDARD \
--provisioning-model=SPOT \
--instance-termination-action=DELETE \
--zone asia-northeast1-a \
--tags tag01 \
--metadata startup-script="#! /bin/bash
sudo apt-get update
sudo apt-get install apache2 -y
sudo service apache2 restart
echo '<!doctype html><html><body><h1>vm01</h1></body></html>' | tee /var/www/html/index.html"
gcloud compute instances create vm02 \
--image-family debian-10 \
--image-project debian-cloud \
--machine-type=n1-standard-1 \
--network-interface=network-tier=STANDARD \
--provisioning-model=SPOT \
--instance-termination-action=DELETE \
--zone asia-northeast1-a \
--tags tag01 \
--metadata startup-script="#! /bin/bash
sudo apt-get update
sudo apt-get install apache2 -y
sudo service apache2 restart
echo '<!doctype html><html><body><h1>vm02</h1></body></html>' | tee /var/www/html/index.html"
gcloud compute instances list
gcloud compute firewall-rules create fw01 \
--target-tags tag01 \
--allow tcp:80
gcloud compute firewall-rules list
curl http://192.0.2.1
curl http://192.0.2.2
-- 3. 負荷分散サービスの構成
-- 3.1 静的外部IPアドレスの作成
gcloud compute addresses create pip01 \
--region asia-northeast1
gcloud compute addresses list
-- 3.2 レガシー HTTP ヘルスチェック リソースの作成
gcloud compute http-health-checks create hc01
gcloud compute http-health-checks list
-- 3.3 ターゲット プールの作成
gcloud compute target-pools create pool01 \
--region asia-northeast1 \
--http-health-check hc01
gcloud compute target-pools list
-- 3.4 インスタンスをターゲットプールに追加
gcloud compute target-pools add-instances pool01 \
--instances vm01,vm02 \
--instances-zone asia-northeast1-a
gcloud compute target-pools describe pool01
-- 3.5 転送ルールの作成
gcloud compute forwarding-rules create rule01 \
--region asia-northeast1 \
--ports 80 \
--address pip01 \
--target-pool pool01
gcloud compute forwarding-rules list
-- 4. 動作確認
gcloud compute forwarding-rules describe rule01 \
--region asia-northeast1
while true; do curl -m1 192.0.2.3; done
-- 5. クリーンアップ
gcloud projects list
gcloud projects delete project01-9999999