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:
You must enable update on repair.
Regional MIGs with the following configuration aren't supported:
MIGs with
EVENorANY_SINGLE_ZONEtarget distribution shapes.MIGs with stateful configuration.
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
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- 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. After installation, initialize the Google Cloud CLI by running the following command:
gcloud initIf 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
In the Google Cloud console, go to the Instance groups page.
If you already have a MIG, do the following:
- Click the name of the MIG.
- Click Edit.
If you don't have a MIG yet, do the following:
- Click Create instance group.
- Enter a Name.
- Select an Instance template.
- In the Location section, select Multiple zones, and then select a region and zones.
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.
In the VM instance lifecycle section, make sure that the following fields are set as follows:
The Default action on failure list is set to Repair instance.
The Updates during VM instance repair is set to Update the instance configuration.
In the Change zone during VM instance repair section, select the Allow repair of VMs in an alternate zone checkbox.
For the other settings, you can either use the default values or modify the fields.
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
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 \
--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
- For a regional instance template:
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.REGION: the region where the MIG is located.
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,
"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
- For a regional instance template:
SIZE: the target size of the MIG.
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
In the Google Cloud console, go to the Instance groups page.
Click the name of the MIG.
Click Edit.
Go to the VM instance lifecycle section.
In the Change zone during VM instance repair section, clear the Allow repair of VMs in an alternate zone checkbox.
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
- Check the repair configuration in a MIG
- Check the zone of a VM by listing the managed instances