Stay organized with collections Save and categorize content based on your preferences.
This document describes how to selectively apply configuration updates to the virtual machine (VM) instances in a managed instance group (MIG).
Compute Engine maintains the VMs in a MIG based on the configuration components that you use: instance template, optional all-instances configuration, and optional stateful configuration.
Whenever you update a MIG's VM configuration by changing 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, you can set up a selective update–also known as a "opportunistic" update type. This type of update offers the following advantages:
Alternatively, if you want to automate the rollout of a new configuration to all or to a random subset of the VMs in a MIG, see Automatically apply VM configuration updates in a MIG. To help you decide, see Methods to apply a new configuration to existing VMs.
Before you beginSelect the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloudInstall the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.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. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
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.
Ensure your group's update policy type is set to "opportunistic" to prevent the MIG from automatically applying new a VM configuration to existing VMs. For more information, see Check your group's update policy type.
Then use the gcloud CLI or REST to update your MIG's configuration and to apply the latest configuration to specific VMs in the group or to all VMs in the group.
Permissions required for this taskTo perform this task, you must have the following permissions:
instanceGroupManagers.patch
methodregionInstanceGroupManagers.patch
methodTo set up a new instance template for your group, you can use the set-instance-template
command.
gcloud compute instance-groups managed set-instance-template INSTANCE_GROUP_NAME \ --template=INSTANCE_TEMPLATE
Apply configuration to specific VMs
To apply the updated configuration to specific VMs, use the update-instances
command with the --instances
flag.
gcloud compute instance-groups managed update-instances INSTANCE_GROUP_NAME \ --instances INSTANCE_NAMES \ --most-disruptive-allowed-action DISRUPTION_LEVEL \ --minimal-action DISRUPTION_LEVEL
Apply configuration to all VMs
To apply the updated configuration to all VMs, use the update-instances
command with the --all-instances
flag.
gcloud compute instance-groups managed update-instances INSTANCE_GROUP_NAME \ --all-instances \ --most-disruptive-allowed-action DISRUPTION_LEVEL \ --minimal-action DISRUPTION_LEVEL
Replace the following:
INSTANCE_GROUP_NAME
: the name of the MIGINSTANCE_TEMPLATE
: new instance templateINSTANCE_NAMES
: a list of VMs to apply the template toDISRUPTION_LEVEL
: the minimal or maximal disruption level: none
, refresh
, restart
, or replace
none
replace
To set up a new instance template for your group, call the patch
method on a zonal or regional MIG and update the versions.instanceTemplate
field. To avoid automatically rolling out the new template to all VMs in the group, set the updatePolicy.type
field to OPPORTUNISTIC
.
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME { "updatePolicy": { "type": "OPPORTUNISTIC" }, "versions": [{ "instanceTemplate": "global/instanceTemplates/NEW_TEMPLATE", }] }
Apply configuration to specific VMs
To apply the updated configuration to specific VMs, call the applyUpdatesToInstances
method for your zonal or regional MIG and specify a list of VMs in the request.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/applyUpdatesToInstances { "instances": [ "zones/ZONE/instances/INSTANCE_NAME_1", "zones/ZONE/instances/INSTANCE_NAME_2" ], "minimalAction": DISRUPTION_LEVEL, "mostDisruptiveAllowedAction": DISRUPTION_LEVEL }
Apply configuration to all VMs
To apply the updated configuration to all existing VMs, set the allInstances
field to true
:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/applyUpdatesToInstances { "allInstances": true, "minimalAction": DISRUPTION_LEVEL, "mostDisruptiveAllowedAction": DISRUPTION_LEVEL }
Replace the following:
INSTANCE_GROUP_NAME
: the name of the groupNEW_TEMPLATE
: the name of the new templateZONE
: the zone of an instance to updateINSTANCE_NAME_1
and INSTANCE_NAME_2
: the names of the VMs to updateDISRUPTION_LEVEL
: the minimal or maximal disruption level: NONE
, REFRESH
, RESTART
, or REPLACE
minimalAction
is NONE
.mostDisruptiveAllowedAction
is REPLACE
.Similar to other managed instance group methods, applyUpdatesToInstances
is intent-based, which means it returns an operation response. The operation can take some time to complete.
After you make a request, you can check the status to verify that the update is complete.
Control the disruption level during selective updatesDepending on the nature of an update, it might disrupt an instance's state. For example, changing an instance's boot disk requires replacing the instance. You can control the level of disruption during a selective update by setting the following options:
Minimal action: Use this option to minimize disruption as much as possible or to apply a more disruptive action than is necessary.
NONE
. If your update requires a more disruptive action, Compute Engine performs the necessary action to execute the update.RESTART
or REPLACE
. For example, Compute Engine does not need to restart a VM to change its metadata. But if your application reads instance metadata only when a VM is restarted, you can set the minimal action to RESTART
in order to pick up metadata changes.Most disruptive allowed action: Use this option to prevent an update if it requires more disruption than you can afford. If your update requires a more disruptive action than you set with this flag, the update request fails. For example, if you set the most disruptive allowed action to RESTART
, then an attempt to update the boot disk image fails because that update requires instance recreation, a more disruptive action than a restart.
When updating selected VMs, both of these options accept the following values:
Value Description Which instance properties can be updated?NONE
Do not disrupt the instance at all. None REFRESH
Do not stop the instance. Additional disks, instance metadata, labels, tags RESTART
Stop the instance and start it again. Additional disks, instance metadata, labels, tags, machine type REPLACE
Delete the instance and create it again. All instance properties stored in the instance template or per-instance configuration
The most disruptive allowed action can't be less disruptive than the minimal action.
When you selectively update VMs, the following defaults apply:
NONE
, which limits disruption as much as possible.REPLACE
. If you cannot tolerate such disruption, set the most disruptive allowed action to be less disruptive.Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This document explains how to selectively update the configuration of virtual machines (VMs) within a managed instance group (MIG), allowing control over which VMs are updated and when."],["Selective updates, also known as \"opportunistic\" updates, enable users to choose specific VMs for updates, manage the update timing, and use gcloud CLI or REST for immediate updates."],["The gcloud CLI or REST API can be used to update either specific VMs or all VMs within a MIG to a new configuration."],["Users can manage the level of disruption during selective updates by specifying a minimal action (e.g., `NONE`, `REFRESH`, `RESTART`) and a most disruptive allowed action (e.g., `REPLACE`), with defaults being `NONE` and `REPLACE` respectively."],["Before doing any updates, you must set your instance group update policy to opportunistic to prevent automatic updates, then set the updated information accordingly, as well as the required permissions to run these updates."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4