This page explains how you can configure the virtual machine (VM) instances in a managed instance group (MIG) and the methods you can use to apply the configuration to existing VMs in the group.
You specify the intended configuration for the VMs in a MIG by using the following VM configuration components:
Whenever you update the intended configuration by using those components, Compute Engine automatically applies your updated configuration to new VMs that are added to the group.
To apply an updated configuration to existing VMs, use the methods described on this page:
You can also configure your MIG to apply the latest available configuration to VMs during VM repairs. For more information, see Apply configuration updates during repairs.
If you only need to resize a MIG, see the documentation for how to add or remove VMs in a MIG. If you want to learn about configuring MIG features, see the docs for autoscaling, autohealing, load balancing, and stateful workloads.
Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
You configure the VMs in a MIG through the following components:
| Component | Properties | Use case |
|---|---|---|
| Instance template | Machine type, boot disk image, labels, startup script, network interfaces, and other VM properties | Required: Use an instance template to define required and
optional instance properties for all VMs in the group. Optional: If you want to canary test a second VM configuration, you can add a second instance template to the group and apply it to a subset of the VMs in the group. |
| All-instances configuration | Labels and metadata | Optional: Use an all-instances configuration to quickly override instance template properties for all VMs in the group. |
| Stateful configuration | Stateful disks, IP addresses, and metadata | Optional: If you need to support a stateful workload, add stateful configuration to VMs in the group. |
If you update any configuration for the group through those components, you must apply the updated configuration to existing VMs in the group in order to make the updated configuration effective.
After you update a MIG's VM configuration, you can apply the new configuration to existing VMs in the group by using the following methods:
For more information about setting a MIG's update type, see Set up a proactive or an opportunistic update.
An automatic update type is also known as a proactive update type. When you set the MIG's update type to proactive, the MIG automatically applies updated configurations to VMs as necessary.
Setting the MIG's update type to proactive offers two primary advantages:
To learn how to set the MIG's update type, see Set up a proactive or an opportunistic update.
For more information about automatic rollouts, see Automatically apply VM configuration updates in a MIG.
A selective update type is also known as an opportunistic update type. When you set the MIG's update type to opportunistic, the MIG applies new configurations to existing VMs only when you selectively target specific VMs to be updated.
Setting the MIG's update type to opportunistic offers the following advantages:
In certain scenarios, a selective update type is useful because you don't want to cause instability to the system if it can be avoided. For example, consider the following:
One of the VMs in your MIG goes down and needs to be repaired but you don't want its configuration to change. If you set the MIG's update type to opportunistic and you do not forcefully apply updates during repairs, then Compute Engine repairs the VM using the same configuration that was used to create that VM, even if the original instance template no longer exists.
You have an autoscaled MIG and you want to apply a non-critical update without any urgency. To ensure that Compute Engine does not tear down your existing VMs to apply the update, set the MIG's update type to opportunistic. When scaling in, the autoscaler preferentially terminates VMs with the old configuration. When the group scales out, it creates VMs with the latest configuration.
To learn how to set the MIG's update type, see Set up a proactive or an opportunistic update.
For more information about selectively updating VMs, see Selectively apply VM configuration updates in a MIG.
You can re-create any VM in a MIG. When you do, the MIG applies any updated configuration that has not yet been applied to that VM. For more information, see Re-creating VMs in a MIG.
To apply new configurations to existing VMs automatically, set the MIG's update type to "proactive". To apply new configurations to existing VMs only when you select a VM to be updated, set the MIG's update type to "opportunistic".
Use the Google Cloud console, the Google Cloud CLI, or REST.