Disable and re-enable proactive VM redistribution in a regional MIG


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 or ANY_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

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. 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

  1. In the Google Cloud console, go to the Instance groups page.

    Go to the Instance groups page

  2. Click Create instance group to create a new instance group.
  3. Assign a name and optionally a description to your instance group.
  4. Choose an instance template for the instance group or create a new one.
  5. 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.
  6. Under Location, select Multiple zones.
  7. Choose a region and select the zones you want to use.
  8. To disable proactive instance redistribution, under Instance redistribution, deselect the Allow instance redistribution checkbox.
  9. 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 MIG
  • INSTANCE_TEMPLATE_NAME: the name of the instance template to use for the group
  • TARGET_SIZE: the target size of the group
  • ZONES: 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.

resource "google_compute_region_instance_group_manager" "default" {
  name                      = "example-rmig"
  region                    = "us-east1"
  distribution_policy_zones = ["us-east1-b", "us-east1-c"]
  update_policy {
    type                         = "PROACTIVE"
    minimal_action               = "REFRESH"
    instance_redistribution_type = "NONE"
    max_unavailable_fixed        = 3
  }
  target_size        = 30
  base_instance_name = "instance"
  version {
    instance_template = google_compute_instance_template.default.id
  }
}

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 request
  • REGION: the region for the instance group
  • INSTANCE_GROUP_NAME: the name for the MIG
  • INSTANCE_TEMPLATE_NAME: the name of the instance template to use for the group
  • TARGET_SIZE: the target size of the instance group
  • ZONE: 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

  1. In the Google Cloud console, go to the Instance groups page.

    Go to the Instance groups page

  2. Under the Name column of the list, click the name of the instance group you want to modify.
  3. Click Edit to modify this managed instance group.
  4. Under Instance redistribution, deselect the Allow instance redistribution checkbox.
  5. 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 MIG
  • REGION: 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 request
  • REGION: the region for the instance group
  • INSTANCE_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