Created
August 11, 2023 21:35
-
-
Save bcleenders/3bde0b1c9f7b0ce8d1b366689926ef83 to your computer and use it in GitHub Desktop.
Upgrade a GCP instance group to dual-stack, without restarting/recreating the instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Steps to switch a GCE pool from single-stack IPv4 to dual-stack. | |
# | |
# These steps avoid recreating VMs in a pool; it happens in-place. | |
# Step 1: Switch all existing VMs in the pool | |
# (run once per instance in the group) | |
curl --request PATCH \ | |
'https://compute.googleapis.com/compute/v1/projects/my-project/zones/europe-west1-b/instances/instance-1234/updateNetworkInterface?networkInterface=nic0' \ | |
--header "Authorization: Bearer $(gcloud auth print-access-token)" \ | |
--header 'Accept: application/json' \ | |
--header 'Content-Type: application/json' \ | |
--data '{"stackType":"IPV4_IPV6"}' \ | |
--compressed | |
# Step 2: Create a new instance template using the existing one. Only change the stackType field! | |
# List the original instance template properties with: | |
# gcloud compute instance-templates describe my-instancegroup-1 --format=json | |
curl --request POST \ | |
'https://compute.googleapis.com/compute/v1/projects/my-project/global/instanceTemplates' \ | |
--header "Authorization: Bearer $(gcloud auth print-access-token)" \ | |
--header 'Accept: application/json' \ | |
--header 'Content-Type: application/json' \ | |
--data '{"description":"my instancepool","name":"my-instance-template-20230811","properties":{"canIpForward":false,"disks":[{"autoDelete":true,"boot":true,"deviceName":"my-instancegroup-1-20230722121021","initializeParams":{"diskSizeGb":"300","diskType":"pd-standard","sourceImage":"https://www.googleapis.com/compute/v1/projects/my-project-2/global/images/gceimage-focal-2023-07-21t13-05-58z"},"mode":"READ_WRITE","type":"PERSISTENT"}],"labels":{},"machineType":"e2-standard-4","metadata":{"fingerprint":"LbTYUonF2cc=","items":[]},"networkInterfaces":[{"accessConfigs":[{"name":"External NAT","networkTier":"PREMIUM","type":"ONE_TO_ONE_NAT"}],"stackType":"IPV4_IPV6","network":"https://www.googleapis.com/compute/v1/projects/my-project/global/networks/vpc-1","nicType":"GVNIC","subnetwork":"https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/subnetworks/ipv6-gua-subnet-1"}],"scheduling":{"automaticRestart":true,"onHostMaintenance":"MIGRATE","preemptible":false,"provisioningModel":"STANDARD"},"serviceAccounts":[{"email":"[email protected]","scopes":["https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/userinfo.email"]}],"tags":{"items":[]}}}' \ | |
--compressed | |
# Step 3: Switch the instanceGroupManager to the new template | |
curl --request POST \ | |
'https://compute.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/instanceGroupManagers/my-instancegroup-1/setInstanceTemplate' \ | |
--header "Authorization: Bearer $(gcloud auth print-access-token)" \ | |
--header 'Accept: application/json' \ | |
--header 'Content-Type: application/json' \ | |
--data '{"instanceTemplate":"https://www.googleapis.com/compute/v1/projects/my-project/global/instanceTemplates/my-instance-template-20230811"}' \ | |
--compressed | |
# Step 4: Trigger the upgrade | |
curl --request POST \ | |
'https://compute.googleapis.com/compute/v1/projects/my-project/regions/europe-west1/instanceGroupManagers/my-instancegroup-1/applyUpdatesToInstances' \ | |
--header "Authorization: Bearer $(gcloud auth print-access-token)" \ | |
--header 'Accept: application/json' \ | |
--header 'Content-Type: application/json' \ | |
--data '{"allInstances":true,"mostDisruptiveAllowedAction":"REFRESH"}' \ | |
--compressed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment