Apply configuration updates during repairs


This document describes how to configure your MIG to apply the latest instance template and per-instance configurations when recreating a VM during repair operations. Applying the latest available configuration during a repair operation is also known as update on repair. This document also describes how to check whether update on repair is enabled in your MIG, and if enabled, how to disable update on repair.

By default, during a repair, a MIG recreates a VM using the same instance configuration that was originally used to create the VM. If updates for the group's instance template or per-instance configurations are available, then you have the option to apply these changes to a VM being repaired.

If you want to automatically apply configuration updates to all or a set of VMs (PROACTIVE), or selectively update specific instances (OPPORTUNISTIC), see Applying new configurations to VMs in a MIG.

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.

Configure update on repair

To configure update on repair, use the Google Cloud console, gcloud CLI, or REST.

Console

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

    Go to Instance groups

  2. Click the name of the MIG where you want to configure update on repair.

  3. Click Edit to modify the MIG.

  4. In the VM instance lifecycle section, for Updates during VM instance repair, select Update the instance configuration.

  5. Click Save.

gcloud

For an existing MIG, use the update command:

gcloud compute instance-groups managed update MIG_NAME \
    --force-update-on-repair

For a new MIG, use the create command:

gcloud compute instance-groups managed create MIG_NAME \
    --template INSTANCE_TEMPLATE \
    --size SIZE \
    --force-update-on-repair

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.

REST

For an existing zonal MIG, use the instanceGroupManagers.patch method, or, for an existing regional MIG, use the regionInstanceGroupManagers.patch method.

Make the following call to configure update on repair in an existing zonal MIG:

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

{
"instanceLifecyclePolicy":
  { "forceUpdateOnRepair": YES
  }
}

For a new zonal MIG, use the instanceGroupManagers.insert method, or, for a new regional MIG, use the regionInstanceGroupManagers.insert method.

Make the following call to configure update on repair when creating a zonal MIG:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers
{
"name": "MIG_NAME",
"instanceTemplate": "INSTANCE_TEMPLATE",
"targetSize": SIZE,
"instanceLifecyclePolicy":
  { "forceUpdateOnRepair": YES
  }
}

Replace the following:

  • PROJECT_ID: Your project ID.
  • ZONE: The zone where the MIG is located.
  • 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.

Check whether update on repair is enabled

By default, a MIG does not update a VM during a repair. To check whether update on repair is enabled for your MIG, use the Google Cloud console, gcloud CLI, or REST to view update on repair configuration.

Console

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

    Go to Instance groups

  2. Click the name of the MIG of which you want to check the configuration.

  3. Click Details tab.

  4. In the VM instance lifecycle section, check the option selected for Updates during VM instance repair. If Update the instance configuration is selected, then update on repair is enabled.

gcloud

Use the describe command as follows:

gcloud compute instance-groups managed describe MIG_NAME \
--format="(instanceLifecyclePolicy)"

In the response body, check for the forceUpdateOnRepair field, which has one of the following values:

  • NO: Default. MIG doesn't update VMs when they are repaired.
  • YES: MIG updates the VMs during their repair.

The following is a sample output:

instanceLifecyclePolicy:
 forceUpdateOnRepair: YES

REST

For a zonal MIG, use the instanceGroupManagers.get method, or, for a regional MIG, use the regionInstanceGroupManagers.get method.

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

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

In the response body, check for the instanceLifecyclePolicy.forceUpdateOnRepair field, which has one of the following values:

  • NO: Default. MIG doesn't update VMs when they are repaired.
  • YES: MIG updates the VMs during their repair.

The following is a sample response:

{
...
"name": "example-mig",
"targetSize": 12,
...
"instanceLifecyclePolicy": {
  "forceUpdateOnRepair": "YES"
  },
...
}

Replace the following:

  • PROJECT_ID: Your project ID.
  • ZONE: The zone where the MIG is located.
  • MIG_NAME: The name of the instance group.

Disable update on repair

When your MIG repairs a VM, if you want the MIG to use the original instance template or the per-instance configurations that were used to create the VM, then you must disable update on repair. By default, update on repair is disabled for a MIG.

Use the Google Cloud console, gcloud CLI, or REST to disable update on repair.

Console

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

    Go to Instance groups

  2. Click the name of the MIG where you want to disable update on repair.

  3. Click Edit to modify the MIG.

  4. In the VM instance lifecycle section, for Updates during VM instance repair, select Keep the same instance configuration.

  5. Click Save.

gcloud

Use the update command to set the --no-force-update-on-repair flag as follows:

gcloud compute instance-groups managed update MIG_NAME \
    --no-force-update-on-repair

REST

For a zonal MIG, use the instanceGroupManagers.patch method, or, for a regional MIG, use the regionInstanceGroupManagers.patch method.

For example, to disable update on repair for a zonal MIG, use the following command:

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

Replace the following:

  • PROJECT_ID: Your project ID.
  • ZONE: The zone where the MIG is located.
  • MIG_NAME: The name of the instance group.

What's next