以下の内容はhttps://htn20190109.hatenablog.com/entry/2024/11/09/190240より取得しました。


{GCP Compute Engine}MIG で VM 構成の更新を自動的に適用す

 

https://cloud.google.com/compute/docs/instance-groups/rolling-out-updates-to-managed-instance-groups?hl=ja

 


-- 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 --quiet
gcloud config set compute/zone asia-northeast1-a --quiet

 

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 instance-templates create template01 \
--image-family debian-11 \
--image-project debian-cloud \
--machine-type e2-micro \
--network-interface=network-tier=STANDARD \
--provisioning-model=SPOT \
--instance-termination-action=STOP \
--tags tag01 

gcloud compute instance-templates create template02 \
--image-family debian-11 \
--image-project debian-cloud \
--machine-type e2-micro \
--network-interface=network-tier=STANDARD \
--provisioning-model=SPOT \
--instance-termination-action=STOP \
--tags tag01 \
--metadata startup-script='apt update && apt -y install apache2 && systemctl start apache2'


gcloud compute instance-templates list
gcloud compute instance-templates describe template01


-- 3. マネージドインスタンスグループ作成

gcloud compute instance-groups managed create mig01 \
--template template01 \
--size 3 \
--region asia-northeast1

 

gcloud compute instance-groups list

gcloud compute instance-groups describe mig01 \
--region asia-northeast1 

 

-- 4. ローリング アップデート

gcloud compute instance-groups managed rolling-action start-update mig01 \
--version=template=template02 \
--region asia-northeast1 \
--type proactive \
--max-surge 3 \
--max-unavailable 3


※max-surge、max-unavailable で1を指定すると下記エラー

ERROR: (gcloud.compute.instance-groups.managed.rolling-action.start-update) Could not fetch resource:
 - Invalid value for field 'resource.updatePolicy.maxSurge.fixed': '1'. Fixed updatePolicy.maxSurge for regional managed instance group has to be either 0 or at least equal to the number of zones.

ERROR: (gcloud.compute.instance-groups.managed.rolling-action.start-update) Could not fetch resource:
 - Invalid value for field 'resource.updatePolicy.maxUnavailable.fixed': '1'. Fixed updatePolicy.maxUnavailable for regional managed instance group has to be either 0 or at least equal to the number of zones.

 

-- 5. 動作確認

while : ; do \
    gcloud compute instance-groups managed list-instances mig01 \
    --region asia-northeast1 \
    ; sleep 5; date; done

 

 


-- 6. クリーンアップ

gcloud compute instance-groups managed delete mig01 --region asia-northeast1 -q
gcloud compute instance-templates delete template01  template02 -q

 

gcloud projects list

gcloud projects delete project01-9999999 -q

gcloud beta billing projects unlink project01-9999999

 

 




以上の内容はhttps://htn20190109.hatenablog.com/entry/2024/11/09/190240より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14