Repair a VM in an alternate zone

This document describes how to allow a regional managed instance group (MIG) to repair a virtual machine (VM) instance in an alternate zone when the MIG cannot repair the VM in its original zone. To learn more about repairs in a MIG, see About repairing VMs for high availability.

When you create a regional MIG, you select one or more zones where the MIG distributes its VMs. By default, if a VM in the MIG fails, the MIG tries to repair that VM in its original zone. You can optionally allow the MIG to repair that VM in one of the other selected zones, which is useful in cases where the MIG cannot repair the VM in its original zone. The MIG picks the alternate zone based on available capacity and quota.

Limitations

When you configure a regional MIG to repair a VM in alternate zone, the following limitations apply:

Before you begin

Allow repairs in an alternate zone

To allow a MIG to repair a VM in an alternate zone, select one of the following options:

Console

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

    Go to Instance groups

  2. If you already have a MIG, do the following:

    1. Click the name of the MIG.
    2. Click Edit.
  3. If you don't have a MIG yet, do the following:

    1. Click Create instance group.
    2. Enter a Name.
    3. Select an Instance template.
    4. In the Location section, select Multiple zones, and then select a region and zones.
    5. In the Target distribution shape drop-down, select Balanced or Any.

      • If you select Balanced, in the dialog that appears, click Disable instance redistribution.

      • If you want to select Any, you must first delete the autoscaling configuration. To delete autoscaling, in the Autoscaling mode drop-down, click Delete autoscaling configuration.

  4. In the VM instance lifecycle section, make sure that the following fields are set as follows:

    1. The Default action on failure list is set to Repair instance.

    2. The Updates during VM instance repair is set to Update the instance configuration.

    3. In the Change zone during VM instance repair section, select the Allow repair of VMs in an alternate zone checkbox.

  5. For the other settings, you can either use the default values or modify the fields.

  6. After you finish, click Save for an existing MIG or Create for a new MIG.

gcloud

To configure an existing MIG to repair VM in an alternate zone, use the update command:

gcloud compute instance-groups managed update MIG_NAME \
    --on-repair-allow-changing-zone=YES \
    --force-update-on-repair \
    --region=REGION

To create a MIG that can repair VM in an alternate zone, use the create command:

gcloud compute instance-groups managed create MIG_NAME \
    --template=INSTANCE_TEMPLATE_URL \
    --size=SIZE \
    --zones=ZONES \
    --target-distribution-shape=SHAPE \
    --instance-redistribution-type=none \
    --on-repair-allow-changing-zone=YES \
    --force-update-on-repair

Replace the following:

  • MIG_NAME: the name of the MIG.
  • INSTANCE_TEMPLATE_URL: the URL of the instance template that you want to use to create instances in the MIG. The URL can contain either the ID or name of the instance template. Specify one of the following values:
    • For a regional instance template: projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
    • For a global instance template: INSTANCE_TEMPLATE_ID
  • SIZE: the target size of the MIG.
  • ZONES: the list of zones in a region where you want to create the VMs in the MIG.
  • SHAPE: the target distribution shape. This value can be either balanced or any.
  • REGION: the region where the MIG is located.

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 MIG that can repair VM in an alternate zone, use the google_compute_region_instance_group_manager resource.

resource "google_compute_region_instance_group_manager" "default" {
  provider           = google-beta
  name               = "example-rmig"
  base_instance_name = "example-rmig-instance"
  region             = "us-central1"

  target_size                      = 3
  distribution_policy_target_shape = "BALANCED"

  version {
    instance_template = google_compute_instance_template.default.id
  }

  instance_lifecycle_policy {
    default_action_on_failure = "REPAIR"
    force_update_on_repair    = "YES"
    on_repair {
      allow_changing_zone = "YES"
    }
  }

  update_policy {
    instance_redistribution_type = "NONE"
    type                         = "OPPORTUNISTIC"
    minimal_action               = "REPLACE"
    max_surge_fixed              = 0
    max_unavailable_fixed        = 6
  }
}

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.

REST

To configure an existing MIG to repair VM in an alternate zone, use the regionInstanceGroupManagers.patch method:

PATCH https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/MIG_NAME
{
    "instanceLifecyclePolicy": {
      "onRepair": {
        "allowChangingZone": "YES"
      },
      "forceUpdateOnRepair": "YES"
    }
}

To create a MIG that can repair VM in an alternate zone, use the regionInstanceGroupManagers.insert method:

POST https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers

{
  "name": "MIG_NAME",
  "instanceTemplate": "INSTANCE_TEMPLATE_URL",
  "targetSize": SIZE,
  "distributionPolicy": {
    "targetShape": "SHAPE"
  }
  "updatePolicy": {
    "instanceRedistributionType": none
  }
  "instanceLifecyclePolicy": {
    "forceUpdateOnRepair": "YES",
    "onRepair": {
      "allowChangingZone": "YES"
    }
  }
}

Replace the following:

  • PROJECT_ID: your project ID.
  • REGION: the region where the MIG is located.
  • MIG_NAME: the name of the MIG.
  • INSTANCE_TEMPLATE_URL: the URL of the instance template that you want to use to create instances in the MIG. The URL can contain either the ID or name of the instance template. Specify one of the following values:
    • For a regional instance template: projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
    • For a global instance template: INSTANCE_TEMPLATE_ID
  • SIZE: the target size of the MIG.
  • SHAPE: the target distribution shape. This value can be either BALANCED or ANY.

Disallow repairs in an alternate zone

If you configured a MIG to repair VM in an alternate zone, then you can restore the default setting in which the MIG repairs the VM in the original zone.

To disallow repairs in an alternate zone, select one of the following options:

Console

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

    Go to Instance groups

  2. Click the name of the MIG.

  3. Click Edit.

  4. Go to the VM instance lifecycle section.

  5. In the Change zone during VM instance repair section, clear the Allow repair of VMs in an alternate zone checkbox.

  6. Click Save.

gcloud

To disallow repairs in an alternate zone, use the update command:

gcloud compute instance-groups managed update MIG_NAME \
    --on-repair-allow-changing-zone=NO \
    --region=REGION

Replace the following:

  • MIG_NAME: the name of the MIG.
  • REGION: the region where the MIG is located.

REST

To disallow repairs in an alternate zone, use the regionInstanceGroupManagers.patch method:

PATCH https://compute.s3nsapis.fr/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/MIG_NAME
{
    "instanceLifecyclePolicy": {
      "onRepair": {
        "allowChangingZone": "NO"
      }
    }
}

Replace the following:

  • PROJECT_ID: your project ID.
  • REGION: the region where the MIG is located.
  • MIG_NAME: the name of the MIG.

What's next