Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Compute Engine: How to change instance template

I have a Google Compute Engine group, Group. I have changed the template that group uses repeatedly, it is now on Template5. The group has one instance, Instance, which is using a previous template (Template4). Template4 has been deleted and no longer exists. I do not see a way to force Instance to change templates. Things I have tried/have been blocked from trying:

  • Editing the template instead of deleting and creating a new ones. Templates do not appear to be editable.
  • Changing the instance group template. I have done this, it hasn't affected the instance template.
  • Creating a new instance within the group and hope it picks up the new template. Obviously there is a way to do this, but the create-instance screen doesn't let me set a group, and the group screen doesn't have a "create new instance" button. It would also fail because Template5 includes using an external disk, and that can only be used by one instance at a time, but if the creation worked I can delete the old instance.
  • Restarting the instance.
  • Editing the instance. The template is not changeable in the edit screen.
like image 441
Elizabeth Van Nostrand Avatar asked Jan 12 '17 20:01

Elizabeth Van Nostrand


People also ask

How do I change my instance template?

So you cannot update an existing instance template or change an instance template after you create it. If you need to make changes to the configuration, create a new instance template. You can create a template based on an existing instance template, or based on an existing instance.


1 Answers

Instance template resources are immutable in GCP. You can edit/change the managed instance groups only by creating a new instance template.

Once you add the new template to the managed instance group either using the console or you can do it in gcloud by executing this command:

gcloud compute instance-groups managed set-instance-template \
<name-of-managed-instance-group> --template=<new-template-name> \
[--region=REGION | --zone=ZONE] [GLOBAL-FLAG …]

Now, all the instances that are to be created after adding this template, will follow the rules in instance template. But, this addition of instance template will not affect the existing instances in the group i.e the instances that use the old instance template. You need to recreate those instances by typing the following command in gcloud:

gcloud compute instance-groups managed recreate-instances \
<name-of-managed-instance-group> --instances \
<name-of-the-existing-instances-separated-by-comma>
[--region=REGION | --zone=ZONE] [GLOBAL-FLAG …]
like image 155
Lakshman Diwaakar Avatar answered Nov 12 '22 08:11

Lakshman Diwaakar