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

  • If you haven't already, set up authentication . 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

    1. 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 .

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

      If you're using a local shell, then create local authentication credentials for your user account:

      gcloud  
      auth  
      application-default  
      login

      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 .

    For more information, see Authenticate for using REST in the Google Cloud authentication documentation.

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 Google Cloud console, go to the Instance groupspage.

    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 Locationsection, select Multiple zones, and then select a region and zones.
    5. In the Target distribution shapedrop-down, select Balancedor 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 modedrop-down, click Delete autoscaling configuration.

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

    1. The Default action on failurelist is set to Repair instance.

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

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

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

  6. After you finish, click Savefor an existing MIG or Createfor a new MIG.

gcloud

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

gcloud beta 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 beta create command :

gcloud beta 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 VMs 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 beta regionInstanceGroupManagers.patch method :

PATCH https://compute.googleapis.com/compute/beta/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 beta regionInstanceGroupManagers.insert method :

POST https://compute.googleapis.com/compute/beta/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 VMs 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 Google Cloud console, go to the Instance groupspage.

    Go to Instance groups

  2. Click the name of the MIG.

  3. Click Edit.

  4. Go to the VM instance lifecyclesection.

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

  6. Click Save.

gcloud

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

gcloud beta 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 beta regionInstanceGroupManagers.patch method :

PATCH https://compute.googleapis.com/compute/beta/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

Design a Mobile Site
View Site in Mobile | Classic
Share by: