In a regional managed instance group (MIG), to maintain an even number of virtual machine (VM) instances across the selected zones in the region, use proactive instance redistribution. This configuration option maximizes the availability of your application in the event of a zone-level failure.
Proactive instance redistribution is turned on by default for regional MIGs. When proactive instance redistribution is turned off, the group does not attempt to proactively redistribute VMs across zones. Turning off proactive instance redistribution is useful if you need to:
- Delete or abandon VMs from the group without affecting other running VMs. For example, you can delete a batch worker VM after job completion without affecting other workers.
- Protect VMs with stateful workloads from unwanted automatic deletion due to proactive redistribution.
- Set the MIG's target distribution shape to
BALANCED
orANY_SINGLE_ZONE
.
You can disable proactive instance redistribution when creating a regional MIG. You can also enable or disable it for an existing regional MIG.
Before you begin
-
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified 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, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
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, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Creating a group with proactive instance redistribution disabled
To create a regional MIG with proactive instance redistribution disabled, use the Google Cloud console , the gcloud CLI, Terraform or REST.
Console
- In the Google Cloud console, go to the Instance groups page.
- Click Create instance group to create a new instance group.
- Assign a name and optionally a description to your instance group.
- Choose an instance template for the instance group or create a new one.
- Specify the number of VMs for this group. For highly available workloads, remember to provision enough VMs to support your application if a zone failure happens.
- Under Location, select Multiple zones.
- Choose a region and select the zones you want to use.
- To disable proactive instance redistribution, under Instance redistribution, deselect the Allow instance redistribution checkbox.
- Continue with the rest of the MIG creation process.
gcloud
To create a new regional MIG without proactive instance
redistribution, use the
gcloud compute instance-groups managed create
command
with the --instance-redistribution-type
flag set to NONE
.
gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \ --template INSTANCE_TEMPLATE_NAME \ --size TARGET_SIZE \ --zones ZONES \ --instance-redistribution-type NONE
Replace the following:
INSTANCE_GROUP_NAME
: the name for the MIGINSTANCE_TEMPLATE_NAME
: the name of the instance template to use for the groupTARGET_SIZE
: the target size of the groupZONES
: the list of zones in a single region where you want to deploy VMs
For example:
gcloud compute instance-groups managed create example-rmig \ --template example-template \ --size 30 \ --zones us-east1-b,us-east1-c \ --instance-redistribution-type NONE
Terraform
If you haven't already created an instance template, which specifies the machine type, boot disk image, network, and other VM properties that you want for each VM in your MIG, create an instance template.
To create a regional MIG, use the
google_compute_region_instance_group_manager
resource.
To disable proactive instance redistribution in a regional MIG, include the
update_policy
block, and set the instance_redistribution_type
field to
NONE
.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
REST
To create a non-autoscaled regional MIG without proactive
instance redistribution, make a POST
request to the
regionInstanceGroupManagers.insert
method. In the request body, include the updatePolicy
property, and set
its instanceRedistributionType
field to NONE
.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME { "name": "INSTANCE_GROUP_NAME", "instanceTemplate": "global/instanceTemplates/INSTANCE_TEMPLATE_NAME", "targetSize": TARGET_SIZE, "distributionPolicy": { "zones": [ {"zone": "zones/ZONE"}, {"zone": "zones/ZONE"} ] }, "updatePolicy": { "instanceRedistributionType": "NONE" } }
Replace the following:
PROJECT_ID
: the project ID for this requestREGION
: the region for the instance groupINSTANCE_GROUP_NAME
: the name for the MIGINSTANCE_TEMPLATE_NAME
: the name of the instance template to use for the groupTARGET_SIZE
: the target size of the instance groupZONE
: the name of a zone in the single region where you want to deploy VMs
Turning off proactive instance redistribution
To disable or re-enable proactive instance redistribution, use the Google Cloud console , the gcloud CLI or REST.
Console
- In the Google Cloud console, go to the Instance groups page.
- Under the Name column of the list, click the name of the instance group you want to modify.
- Click Edit to modify this managed instance group.
- Under Instance redistribution, deselect the Allow instance redistribution checkbox.
- Click Save.
gcloud
To turn off proactive instance redistribution, use the
compute instance-groups managed update
command
and set the --instance-redistribution-type
flag to NONE
as follows:
gcloud compute instance-groups managed update INSTANCE_GROUP_NAME \ --instance-redistribution-type NONE \ --region REGION
Replace the following:
INSTANCE_GROUP_NAME
: the name of the MIGREGION
: the region of the instance group
REST
To turn off proactive instance redistribution, use the
regionInstanceGroupManagers.patch
method
and set the instanceRedistributionType
field to NONE
as follows:
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME { "updatePolicy": { "instanceRedistributionType": "NONE" } }
Replace the following:
PROJECT_ID
: the project ID for this requestREGION
: the region for the instance groupINSTANCE_GROUP_NAME
: the name of the MIG
Turning on proactive instance redistribution
To turn on proactive instance redistribution, use a similar command as for
turning off proactive instance redistribution,
but set the instance redistribution type to PROACTIVE
.
If you manually deleted or abandoned some managed instances resulting in an uneven distribution of VMs across the region, then, before you can re-enable proactive instance redistribution, you must manually rebalance the group. The difference in the number of VMs between any two zones shouldn't exceed 1 VM.
A regional MIG does not allow turning on proactive instance redistribution when VMs are distributed unevenly across zones (the difference in the number of VMs between two zones is 2 or more VMs). This is to prevent an unintended automatic deletion of VMs from zones with more VMs, which would be triggered to achieve even distribution.
What's next
- Learn about Viewing info about MIGs and their VMs.
- Learn about Working with VMs in a MIG, including adding, recreating, and removing instances.