Turn off repairs in a MIG


This document describes how to turn off repairs in a managed instance group (MIG) and, if already turned off, how to set the MIG back to repairing VMs.

By default, a MIG automatically repairs a failed VM in the group by recreating that VM. If you've configured an application-based health check, then the MIG repairs unhealthy VMs on which your application has failed the health check.

If you don't want a MIG to repair a failed or an unhealthy VM, you can turn off repairs. Turning off repairs is useful in scenarios when you want to troubleshoot a failed VM, implement your own repair logic, or monitor application health without repairing of unhealthy VMs by the MIG.

To check whether repairs are already turned off in a MIG, see check whether repairs are turned off in a MIG.

For more information about repairs in a MIG, see About repairing VMs for high availability.

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.

Limitations

You cannot turn off repairs in a MIG if your group has the following:

Turn off repairs in a MIG

Turning off repairs in a MIG turns off both automatic repairs and repairs based on an application-based health check (autohealing).

To turn off repairs, 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 Instance groups

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

    1. Click the name of the MIG in which you want to turn off repair.
    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. For the other settings, you can either use the default values or modify the fields.
  4. In the VM instance lifecycle section, set the Default action on failure to No action.

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

gcloud

To turn off repairs in an existing MIG, use the update command:

For example, use the following command to turn off repairs in a zonal MIG:

gcloud compute instance-groups managed update MIG_NAME \
    --zone=ZONE \
    --default-action-on-vm-failure=do_nothing

To turn off repairs when creating a MIG, use the create command:

For example, use the following command to turn off repairs when creating a zonal MIG:

gcloud compute instance-groups managed create MIG_NAME \
    --template=INSTANCE_TEMPLATE \
    --size=SIZE \
    --zone=ZONE \
    --default-action-on-vm-failure=do_nothing

Replace the following:

  • MIG_NAME: The name of the instance group.
  • INSTANCE_TEMPLATE: The name of the instance template to use for the group.
  • SIZE: The target size of the instance group.
  • ZONE: The zone where the MIG is located. For a regional MIG, use the --region flag.

REST

To turn off repairs in an existing MIG, use the API method as follows:

For example, make the following call to turn off repairs in an existing zonal MIG:

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME

{
  "instanceLifecyclePolicy":
    {
      "defaultActionOnFailure": "DO_NOTHING"
    }
}

To turn off repairs when creating a MIG, use the API method as follows:

For example, make the following call to turn off repairs when creating a zonal MIG:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers

{
  "versions": [
    {
      "instanceTemplate": "INSTANCE_TEMPLATE_URL"
     }
  ],
  "name": "MIG_NAME",
  "targetSize": SIZE,
  "instanceLifecyclePolicy":
   {
     "defaultActionOnFailure": "DO_NOTHING"
   }
}

Replace the following:

  • PROJECT_ID: Your project ID.
  • MIG_NAME: The name of the instance group.
  • INSTANCE_TEMPLATE_URL: The partial URL of the instance template that you want to use to create the VMs in the group. For example:
    • Regional instance template: projects/example-project/regions/us-central1/instanceTemplates/example-template.
    • Global instance template: projects/example-project/global/instanceTemplates/example-template.
  • SIZE: The target size of the instance group.
  • ZONE: The zone where the MIG is located. For a regional MIG, use regions/REGION in the URL.

Set a MIG to repair failed and unhealthy VMs

By default, a MIG repairs failed and unhealthy VMs. If you've turned off repairs in a MIG, you can set it back to repairing VMs.

Console

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

    Go to Instance groups

  2. Click the name of the MIG in which you want to set repair.

  3. Click Edit.

  4. In the VM instance lifecycle section, set the Default action on failure to Repair instances.

  5. After you finish, click Save to apply the changes.

gcloud

To set a MIG to repair VMs, use the update command:

gcloud compute instance-groups managed update MIG_NAME \
    --default-action-on-vm-failure=repair

Replace MIG_NAME with the name of a MIG.

REST

To set a MIG to repair VMs, use the API method as follows:

For example, make the following call to turn off repairs in a zonal MIG:

PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME

{
  "instanceLifecyclePolicy":
  {
    "defaultActionOnFailure": "REPAIR"
 }
}

Replace the following:

  • PROJECT_ID: Your project ID.
  • MIG_NAME: The name of the instance group.
  • ZONE: The zone where the MIG is located. For a regional MIG, use regions/REGION in the URL.

What's next