Add and remove VMs from a MIG Stay organized with collections Save and categorize content based on your preferences.
After you'vecreated a managed instance group (MIG),you might want to add or remove VMs from that group to meet your workload'sneeds. If you have reached the defaultlimitfor the maximum number of VMs that you can add to a MIG, and you need more VMs,you canincrease the size limit of the MIG.
To add or remove VMs in a MIG, you can do the following:
- Automatically add or remove VMs by setting the target size of the MIG:
- Use autoscaling for stateless applications
- Create a resize request in the MIG
- Manually set the size of the MIG
- Manually add, remove or abandon specific instances:
Before you begin
- If you haven't already, set upauthentication. Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
Install the Google Cloud CLI. After installation,initialize the Google Cloud CLI by running the following command:
gcloudinit
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
.- Set a default region and zone.
Terraform
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
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.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
REST
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.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.For more information, seeAuthenticate for using REST in the Google Cloud authentication documentation.
Set the group's target size
You can set a MIG's target size automatically by using an autoscaler or set thesize manually.
Automatically adding and removing VMs in a MIG
You can configure managed instance groups to automatically add or removeVMs based on their workloads. Your applications can gracefully handleincreases in traffic, and you can reduce your costs when the need forcompute resources is lower. To start scaling your managed instance groups,seeCreate a MIG with autoscaling.
For more information, seeAutoscaling groups of instances.
Create a resize request
You can use resize requests to add GPU VMs to a MIG all at once. This featurehelps you avoid charges for partial capacity while Compute Engineprovisions all resources. MIG resize requests use the flex-start orreservation-bound provisioning models. These models let you obtain vCPUs andGPUs at a discounted price.
For more information, seeAbout resize requests in a MIG.
Manually setting the size of a MIG
If a managed instance group is not already set toautomatically scale, you can resize the groupmanually to change the number of instances. If you increase thesize, the managed instance group uses the current instance template to add newinstances. If you decrease the size, the managed instance group deletesVMs from the group. The group deletes instances with acurrentAction
ofDELETING
,CREATING
, andRECREATING
before it deletes instances that arerunning with no scheduled actions.
If the group is part of abackend service thathasenabled connection draining,it can take up to an additional 60 seconds after the connection drainingduration has elapsed before the VM instance is removed or deleted.
Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.instanceGroupManagers.update
on the managed instance group
Console
In the Google Cloud console, go to theInstance groups page.
Under theName column of the list, click the name of the instancegroup where you want to change the group size.
ClickEdit to modify this managed instance group.
ClickGroup size & autoscaling to expand the section.
In theNumber of instances field, specify the number of instancesthat you want to include in this managed instance group.
IfAutoscaling is enabled, the group automatically adds orremoves instances as necessary. However, you can change theMinimum number of instances and theMaximum number of instancesvalues to indirectly adjust the group size through autoscaler.
ClickSave to apply the new template.
gcloud
Use theresize
command.
gcloud compute instance-groups managed resizeINSTANCE_GROUP_NAME \ --sizeNEW_SIZE \ --zoneZONE
REST
Call theresize
method for azonalorregionalMIG resource. Specify the new instance group size as a parameter.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resize?size=NEW_SIZE
If the instance group is a regional managed instance group, replacezones/ZONE
withregions/REGION
.
After you make a request to resize a managed instance group, theVMs start or stop as soon as the system can provision or delete them. Thisprocess can take a significant amount of time depending on the number ofinstances in the group.Verify the status of instancesin your managed instance group.
Note: Because new VMs are created with the current instance template,your group can contain dissimilar VMs if you add instancesto the group after you change the instance template. Existing VMs usetheir previous instance templates until yourecreate them,and new VMs use the currently specified instance template for the MIG.Disabling creation retries mode during resize
Beta
This product is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA products are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.
By default, if the initial creation of a VM instance fails,the managed instance group continuously retries to create the VM,until the VM is successfully created. However, if you don't wantautomatic creation retries, you can disable the creation retries mode when youresize the instance group.In this mode, the managed instance group attempts to create all instances onlyonce. If there is anerrorduring instance creation, the managed instance group gives up on this instance,removes it from thegroup'slist of managed instances,and decreases the target size of the managed instance group.
This mode applies only during the first creation attempt of a VM. If aVM is created successfully while this mode is enabled, the VMbehaves the same way as all other VMs created with a regular resizerequest. In particular, if a running VM dies unexpectedly at a later timeand needs to be recreated, this mode does not affect the recreation behavior inthat scenario.
Disabling the creation retries mode is especially useful in scenarios where youhave systems automatically creating groups of VMs where an exact numberof VMs is not required. You might prefer to stabilize quickly on the sizeof the managed instance group and be flexible in the number of VMs in thegroup, rather than to wait indefinitely until all the requested instances arecreated, which might be delayed temporarily or permanently because of quotaerrors or other unrelated issues.
Limitations
- You cannot disable creation retries for a regional MIG with an
EVEN
targetdistribution shape. - For regional MIGs with a
BALANCED
orANY_SINGLE_ZONE
target distributionshape, you must disableproactive instance redistributionbefore you can disable creation retries mode. - You cannot disable creation retries forautoscaled MIGs.
To resize a managed instance group when creation retries mode is disabled, usethe Google Cloud CLI or REST.
Important: Google recommends that you don't concurrently run two resizeoperations with different creation retries modes as it might result in anunexpected target size. For example, if you issue a resize command withoutcreation retries and, before it completes, you issue a second resize commandwith creation retries enabled, the second command does not invalidate the firstone. Some instances are created without retries and if any of them fail,the group's target size decreases accordingly.Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.instanceGroupManagers.update
on the managed instance group
gcloud
Use thebetaresize
commandwith the--no-creation-retries
flag.
gcloud beta compute instance-groups managed resizeINSTANCE_GROUP_NAME \ --sizeNEW_SIZE \--no-creation-retries \ [--regionREGION | --zoneZONE]
Replace the following:
INSTANCE_GROUP_NAME
: The name of the MIG that youwant to resize.NEW_SIZE
: The target number of running instancesin managed instance group.ZONE
: For zonal MIGs, the zone where the MIG islocated.REGION
: For regional MIGs, the region where theMIG is located.
REST
For a zonal MIG, use thebetainstanceGroupManagers.resizeAdvanced
methodor, for a regional MIG, use thebetaregionInstanceGroupManagers.resizeAdvanced
method.Specify the new group size and thenoCreationRetries
field in the requestbody.
For example, make the following call to resize a zonal MIG with creationretries mode disabled.
POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resizeAdvanced{ "targetSize":NEW_SIZE,"noCreationRetries": true}
Replace the following:
PROJECT_ID
: Your project ID.ZONE
: The zone where the MIG is located. For aregional MIG, replacezones/ZONE
withregions/REGION
and specify the region. For moreinformation, seeAbout regional MIGs.INSTANCE_GROUP_NAME
: The name of the MIG that youwant to resize.NEW_SIZE
: The target number of running instancesin the managed instance group.You can see which instances are being created and in which mode by usingthe
listManagedInstances
method. When the creation retries mode isdisabled, instances that you create have acurrentAction
ofCREATING_WITHOUT_RETRIES
.
Add, remove or abandon specific instances
The following sections show how to add, remove, or abandon specific instances ina MIG.
Creating instances with specific names in MIGs
If your workload or orchestration system requires specific instance names, youcan add those instances to an existing MIG. This section shows how to addinstances based on availability. If resources are unavailable, then the MIG addsa portion of the instances and creates the remaining ones when resources becomeavailable. To add GPU instances with specific names all at once to a MIG, seeinsteadCreate a resize request in this document.
The names that you assign to these instances persist if the MIG recreates them.For more information about preserving the state of MIG instances, seestateful MIGs.
Limitations
If you create instances with specific names:
- You mustturn offautoscaling during the instance creation process.
- You must set the MIG's update policy to beopportunistic.
- If you are updating a regional MIG:
- You must disableproactive instance redistribution.
- You can't select which zone to create the VM in.
- You can't use duplicate VM instance names within a project.
You can use thegcloud CLIorRESTto add VMs with specific names to an existing MIG.
Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.instanceGroupManagers.update
on the managed instance group
gcloud
Use theinstance-groups managed create-instance
command.
gcloud compute instance-groups managed create-instanceINSTANCE_GROUP_NAME \ --instanceINSTANCE_NAME \ [--regionREGION | --zoneZONE]
Replace the following:
- INSTANCE_GROUP_NAME is the name of the regional or zonal MIGto add a new instance to.
- INSTANCE_NAME is the name you want to assign to the newinstance.
REST
Send a POST request to theregionInstanceGroupManagers.createInstances
method. For a zonal managed instance group, use theinstanceGroupManagers.createInstances
method. In the request body, include theinstances
field with names forone or more instances.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/createInstances{ "instances": [ { "name": "INSTANCE_NAME_1" }, { "name": "INSTANCE_NAME_2" } ]}
Deleting specific instances from a group
You can delete individual VM instances in a managed instance group. Deletinginstances reduces the specifiedtargetSize
of the instance group and removesthe VMs from anytarget pools of which theyare a member.
Deleting specific instances from a managed instance group doesn't change anyspecified autoscaler settings. If you delete instances from a managed instancegroup, the autoscaler might detect an increase in the workload on the otherinstances in the group and increase the group size back to its previous level.To prevent this,stop the autoscalerbefore attempting to delete the instances.
If the group is part of abackend service thathasenabled connection draining,it can take up to an additional 60 seconds after the connection drainingduration has elapsed before the VM instance is removed or deleted.
Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.instanceGroupManagers.update
on the managed instance group
Console
In the Google Cloud console, go to theInstance groups page.
In theName column of the list, click the name of the instancegroup where you want to delete individual instances. A page opens withthe instance group properties and a list of instances that are includedin the group.
In theVM instances section, select one or more instances that youwant to delete.
ClickDelete.
In the dialog to confirm deletion, type
delete
, and then clickDelete.The MIG deletes the selected instances.
gcloud
To delete an instance with the gcloud CLI, use theinstance-groups managed delete-instances
command.
gcloud compute instance-groups managed delete-instancesINSTANCE_GROUP_NAME \ --instancesINSTANCE_NAME_1,INSTANCE_NAME_2 \ [--regionREGION | --zoneZONE]
The command returns the operation status per instance:
SUCCESS
is returned if the gcloud CLI deleted the instance.FAIL
is returned for all instances if any instance that you specify inthe request is not a member of the group, if any member is already beingdeleted or abandoned, or if the request fails for any other reason.SKIPPED
is returned only if you use the--skip-instances-on-validation-error
flag and the instance is not amember of the group or is already being deleted or abandoned.MEMBER_NOT_FOUND
is returned only for regional groups when thegcloud CLI wasn't able to resolve the zone from the instancename.
If you anticipate that your deletion request might conflict with concurrentoperations, use the--skip-instances-on-validation-error
flag. This flagspecifies whether the request should proceed even if the request includesinstances that are not members of the group or that are already beingdeleted or abandoned—for example, instances that are being deleted by anautoscaler. By default, if you omit this flag and such an instanceis specified in the request, the operation fails. The operation always failsif the request contains a badly formatted instance name or a reference toan instance that exists in a zone or region other than the group's zone orregion.
For example, the following command requests deletion of four instances, butthree of them are no longer in the group:
gcloud compute instance-groups managed delete-instances example-mig \ --instances=example-instance-1,example-instance-2,example-instance-3,example-instance-4 \ --region=us-central1 \--skip-instances-on-validation-error
In this example, three instances didn't pass validation, so they wereskipped, whileexample-instance-3
was deleted:
Updated [https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/instanceGroupManagers/example-mig].PROJECT ZONE INSTANCE STATUS VALIDATION_ERRORexample-project us-central1-a example-instance-1 SKIPPED Cannot delete instance https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-instance-1 that was already deleted.example-project us-central1-a example-instance-2 SKIPPED Cannot delete instance https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-instance-2 that was already abandoned.example-project us-central1-a example-instance-3 SUCCESSexample-project us-central1-a example-instance-4 SKIPPED Cannot find instance https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-instance-4.
If you omit the--skip-instances-on-validation-error
flag and if anyinstance does not pass validation, then no instance is deleted:
gcloud compute instance-groups managed delete-instances example-mig \ --instances=example-instance-1,example-instance-2,example-instance-3,example-instance-4 \ --region=us-central1Updated [https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/instanceGroupManagers/example-mig].PROJECT ZONE INSTANCE STATUSexample-project us-central1-a example-instance-1 FAILexample-project us-central1-a example-instance-2 FAILexample-project us-central1-a example-instance-3 FAILexample-project us-central1-a example-instance-4 FAIL
REST
Send a POST request to theregionInstanceGroupManagers.deleteInstances
method. For a zonal managed instance group, use theinstanceGroupManagers.deleteInstances
method.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/deleteInstances{ "instances": [ "zones/ZONE/instances/INSTANCE_NAME_1", "zones/ZONE/instances/INSTANCE_NAME_2" ]}
If you anticipate that your deletion request might conflict with concurrentoperations, use theskipInstancesOnValidationError
field. This fieldspecifies whether the request should proceed even if the request includesinstances that are not members of the group or that are already beingdeleted or abandoned—for example, instances that are being deleted by anautoscaler. By default, if you omit this flag and such an instanceis specified in the request, the operation fails. The operation always failsif the request contains a badly formatted instance name or a reference toan instance that exists in a zone or region other than the group's zone orregion.
For example, the following request to delete 2 instances will succeed evenif one of the instances is already deleted or being deleted:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/deleteInstances{ "instances": [ "zones/ZONE/instances/INSTANCE_NAME_1", "zones/ZONE/instances/INSTANCE_NAME_2" ],"skipInstancesOnValidationError": true}
You can view instances that were skipped in the operation by viewing theoperation. For regional MIGs, use theregionOperations.get
method.For zonal MIGs, use thezoneOperations.get
method.Warnings are listed in the operation's warning field.
After you make a request to delete instances in a managed instance group,the instances stop as soon as the system can delete them. This process can takea significant amount of time depending on the number of instances that youdelete from the group.Verify the status of the grouporverify the status of the managed instances.
Abandoning instances from a MIG
You can separate a VM instance from a managed instance group todebug issues with individual instances without affecting the group as a whole.Abandoning an instance from a group also removes the instance fromload balancers that were assigned to themanaged instance group.Target pools that weremanually assigned to specific individual instances are not removed.
You cannot add an abandoned VM instance back to the group.Abandoning instances reduces the specifiedtargetSize
of the instance group,but doesn't change any specified autoscaler settings. Managed instance groupswith an autoscaler continue to add or remove instances automatically asnecessary. For a regional MIG with autoscaling set toONLY_SCALE_OUT
mode,if you abandon a VM instance to reduce the MIG target size to theautoscaler's recommended size, thenthe autoscaler might create a new VM instance in the same zone of the abandonedVM. In such cases, to avoid creation of a new VM instance, try abandoning VMinstance from a different zone.
If the group is part of abackend service thathasenabled connection draining,it can take up to an additional 60 seconds after the connection drainingduration has elapsed before the VM instance is removed or deleted.
Permissions required for this task
To perform this task, you must have the followingpermissions:
compute.instanceGroupManagers.update
on the managed instance group
Console
In the Google Cloud console, go to theInstance groups page .
In theName column of the list, click the name of the instancegroup from which you want to remove instances. A page opens with theinstance group properties and a list of instances that are included inthe group.
In theVM instances section, select one or moreinstances that you want to remove from the group.
ClickRemove from group.
In the dialog to confirm the removal of selected instances, type
remove
, and then clickRemove.The MIG removes the selected instances from the group. The removedinstances continue to run outside of the group.
gcloud
To remove an instance from the instance groupwithout deleting the VM, use theinstance-groups managed abandon-instances
command.
gcloud compute instance-groups managed abandon-instancesINSTANCE_GROUP_NAME \ --instancesINSTANCE_NAME_1,INSTANCE_NAME_2 \ [--regionREGION | --zoneZONE]
REST
Send a POST request to theregionInstanceGroupManagers.abandonInstances
method. For a zonal managed instance group, use theinstanceGroupManagers.abandonInstances
method.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME/abandonInstances{ "instances": [ "zones/ZONE/instances/INSTANCE_NAME_1", "zones/ZONE/instances/INSTANCE_NAME_2" ]}
After you make a request to abandon instances from a managed instance group,the group removes the instances as soon as possible.Verify the status of the grouporverify the status of the managed instances.
Increase the group's size limit
By default, the size limit for a zonal MIG is 1,000 VMs, and the size limit fora regional MIG is 2,000 VMs. You can further increase these limits to 2,000 VMsfor a zonal MIG and 4,000 VMs for a regional MIG.
To increase the limits, set the group'slistManagedInstancesResults
field toPAGINATED
. If you still need more VMs in the group, create multiple MIGs orcontact support.
listManagedInstancesResults
field toPAGINATED
, thelistManagedInstances
method changes its behavior.With the defaultPAGELESS
setting, the list method ignores themaxResults
query parameter and always returns all the instances. With thePAGINATED
setting, the list method returns paginated result withmaxResults
capped at500 like other lists in Compute Engine. You need to make sure that allcalls to these methods are aware of pagination and use thepageToken
queryparameter to page through large list of instances.There is no impacton Google Cloud CLI or the Google Cloud console which already fully supportpagination.
Console
In the Google Cloud console, go to theInstance groups page.
In theName column of the list, click the name of the instancegroup of which you want to increase the size limit.
ClickEdit to modify the instance group.
ClickAdvanced Options to expand the section.
In theManaged instance list API call results section, selectPaginated.
ClickSave to apply the changes.
gcloud
For an existing MIG, use theupdate
command:
gcloud compute instance-groups managed updateINSTANCE_GROUP_NAME \--list-managed-instances-results=PAGINATED
For a new MIG, use thecreate
command:
gcloud compute instance-groups managed createINSTANCE_GROUP_NAME \ --templateINSTANCE_TEMPLATE \ --sizeSIZE \--list-managed-instances-results=PAGINATED
Terraform
To increase a MIG's size limit, set thelist_managed_instances_results
argument toPAGINATED
.
The following sample increases the size limit of azonal MIG. For more information about the resource used in the sample, seethegoogle_compute_instance_group_manager
resource.For a regional MIG, use thegoogle_compute_region_instance_group_manager
resource.
resource "google_compute_instance_group_manager" "default" { name = "my-igm" base_instance_name = "test" target_size = 7 zone = "us-central1-f" list_managed_instances_results = "PAGINATED" version { instance_template = google_compute_instance_template.default.id name = "primary" }}
To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.
REST
For an existing zonal MIG, use theinstanceGroupManagers.patch
methodor, for a regional MIG, use theregionInstanceGroupManagers.patch
method–forexample:
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/regionInstanceGroupManagers/INSTANCE_GROUP_NAME{ "listManagedInstancesResults": "PAGINATED",}
For a new zonal MIG, use theinstanceGroupManagers.insert
methodor, for a regional MIG, use theregionInstanceGroupManagers.insert
method.
If you want to switch back to pageless list results, you must also revertto the group's default size limit. To switch back, first ensure that thegroup does not exceed its default size limit, then set thelistManagedInstancesResults
field toPAGELESS
.
What's next
- Learn aboutworking with managed instances,for example, to delete, abandon, and recreate managed instances.
- View info aboutmanaged instance groups and managed instances.
- Troubleshoot managed instance groups.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-02 UTC.