How to update managed instance group ?
You can gradually upgrade an instance in an instance group to a new instance template. This type of upgrade is called as Rolling upgrade. Let us say we have 10 instances running and we want to upgrade only 2 instances at once. this is the default. We can also set a canary template, meaning if the upgrade of the first two instances is successful & tested. Then all the remaining instances will be upgraded at once.
We can also setup when to update the instances. It can be proactive, meaning immediate. The other option is do an opportunistic upgrade, meaning to update the instance to the new template when the instance group is resized or if any of the instances are killed. You can similarly do a Rolling restart. In a Rolling restart, there is no change in the instance template, but the existing VM is replaced with a new Virtual machine.
Go the instance group and click on update VM
So, instead of updating the instance template 1 to new template. Let us add a new template. We can set target running instances to 1 for testing. Once we test the instance and confirm that it is running as expected, we can change the number from 1 to all instances.
Then if we scroll down a little, we can see the section update configuration. here the default is selective (which is nothing but same as opportunistic) that we talked about earlier. Once we select Automatic (Proactive) option, we will see more options. You have an option to even retain the instance name when the instances are replaced.
You can also configure Max Surge which is how many new instances are created before the old ones are deleted. & also, you can specify maximum unavailable instances meaning, how many instances can be unavailable during the update.
Rolling Restart/Replace:
In case of a Rolling restart or replace, there is no change in the template. You would only need to specify the maximum number of instances that can be unavailable and also max surge (how many instances can be created before old ones are removed). Max-surge is only applicable in case of replace. The option that need to be chosen under the instance groups is Restart/Replace VMS
The options under restart are very simple. We just have only one option to choose the number of instances that can be unavailable, meaning the number of instances that we want to restart at once. In case of replace, we have options of max surge and maximum unavailable instances.