Turn off repairs in a MIG


This document describes how to turn off repairs of failed and unhealthy VMs in a managed instance group (MIG) and, if already turned off, how to configure the MIG to repair 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 also repairs unhealthy VMs on which your application fails the health check. Repairing a VM based on an application-based health check is also called autohealing.

If you don't want a MIG to repair a failed VM or an unhealthy VM, you can turn off repairs in the MIG. 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 unhealthy VMs.

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. After installing the Google Cloud CLI, initialize it 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.

    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.

      After installing the Google Cloud CLI, initialize it 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.

    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

When you turn off repairs in a MIG, by default, both failed VM repairs and autohealing are turned off. If you only want to turn off autohealing, see Turn off autohealing.

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 turn off repair.

  3. Click Edit.

  4. In the VM instance lifecycle section, set the Default action on failure field to No action.

  5. If you've configured autohealing and don't want the MIG to turn off autohealing, set the On failed health check field to Repair instance.

  6. Click Save.

gcloud

To turn off repairs in a MIG, then use the update command as follows. This turns off autohealing by default.

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

If autohealing is configured in the MIG and you don't want to turn off autohealing by default, use the beta update command to set the --action-on-vm-failed-health-check flag to repair. This ensures that autohealing of unhealthy VMs continues to work even if repairing failed VMs is turned off.

gcloud beta compute instance-groups managed update MIG_NAME \
    --default-action-on-vm-failure=do-nothing \
    --action-on-vm-failed-health-check=repair \
    --zone=ZONE

Replace the following:

  • MIG_NAME: the name of the instance group.
  • ZONE: the zone where your MIG is located. For a regional MIG, use the --region=REGION flag.

REST

To turn off repairs in a MIG, then use the API methods as follows. This turns off autohealing by default.

For example, make the following call in a zonal MIG. This turns off autohealing by default.

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

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

If autohealing is configured in the MIG and you don't want to turn off autohealing by default, use the API methods as follows to set the onFailedHealthCheck flag to REPAIR. This ensures that autohealing of unhealthy VMs continues to work even if repairing failed VMs is turned off.

For example, make the following call in a zonal MIG:

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

{
  "instanceLifecyclePolicy":
    {
      "defaultActionOnFailure": "DO_NOTHING",
      "onFailedHealthCheck": "REPAIR"
    }
  }

Replace the following:

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

Turn off autohealing

When you've configured an application health check in a MIG, if you don't want the MIG to repair any unhealthy VMs, you can turn off autohealing separately. This doesn't turn off repairs of failed 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 turn off autohealing.

  3. Click Edit.

  4. In the VM instance lifecycle section, set the On failed health check field to No action.

  5. Click Save.

gcloud

To turn off autohealing in a MIG, use the beta update command and set the --action-on-vm-failed-health-check flag to do-nothing.

For example, use the following command for a zonal MIG:

gcloud beta compute instance-groups managed update MIG_NAME \
    --action-on-vm-failed-health-check=do-nothing \
    --zone=ZONE

Replace the following:

  • MIG_NAME: the name of the MIG.
  • ZONE: the zone where the MIG is located. For a regional MIG, use the --region=REGION flag.

REST

To turn off autohealing in a MIG, use the API methods as follows and set the --action-on-vm-failed-health-check flag to do-nothing.

For example, make the following request to turn off autohealing in a zonal MIG:

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

{
  "instanceLifecyclePolicy":
   {
     "onFailedHealthCheck": "DO_NOTHING"
   }
}

Replace the following:

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

Turn on repairs or autohealing

By default, a MIG repairs failed VMs and, if autohealing is configured, the MIG also repairs unhealthy VMs. If you've turned off repairs or autohealing or both, you can turn them back on again.

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 turn on repair.

  3. Click Edit.

  4. In the VM instance lifecycle section, do the following:

    • To repair failed VMs, set the Default action on failure field to Repair instance.
    • To repair unhealthy VMs, set the On failed health check field to Repair instance. If you set this value to Default action, then autohealing uses the same setting that you configure for the Default action on failure field.
  5. After you finish, click Save to apply the changes.

gcloud

To turn on repairs in a MIG, use the update command. This also turns on autohealing, if the value of the --action-on-vm-failed-health-check flag is default-action.

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

If you've turned off autohealing separately and you want to turn it back on again, use the beta update command:

gcloud beta compute instance-groups managed update MIG_NAME \
    --action-on-vm-failed-health-check=default-action OR repair

Replace the following:

  • MIG_NAME with the name of a MIG.
  • default-action OR repair: If you want autohealing to use the same setting that you configure for repairs of failed VMs, set the value to default-action. For example, when you turn off repairing of failed VMs, the MIG turns off autohealing also. If you want to control repairs of unhealthy VMs separately, set the value to repair.

REST

To turn on repairs in a MIG, use the API method as follows. This also turns on autohealing, if the value of the onFailedHealthCheck field is DEFAULT_ACTION.

For example, make the following request in a zonal MIG:

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME
    {
      "instanceLifecyclePolicy": {
        "defaultActionOnFailure": "REPAIR"
      }
    }
  

If you've turned off autohealing separately and you want to turn it back on again, use the beta API method as follows:

  PATCH https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/MIG_NAME
  {
    "instanceLifecyclePolicy": {
      "onFailedHealthCheck": "DEFAULT_ACTION OR REPAIR"
    }
  }

Replace the following:

  • PROJECT_ID: your project ID.
  • ZONE: the zone where your MIG is located. For a regional MIG, use regions/REGION in the URL.
  • MIG_NAME: the name of the MIG.
  • DEFAULT_ACTION OR REPAIR: If you want autohealing to use the same setting as for repairs of failed VMs, set the value to DEFAULT_ACTION. For example, when you turn off repairing of failed VMs, the MIG turns off autohealing also. If you want to configure autohealing separately, set the value to REPAIR.

What's next