Change or remove instance flexibility


This document describes how to make changes or remove instance flexibility in a managed instance group (MIG) by editing the instance flexibility policy. It also describes how to update a VM's machine type when the machine type is removed from the instance flexibility configuration.

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.

Change instance flexibility configuration

You can make the following changes by editing the instance flexibility configuration in a MIG:

  • Add a machine type to an instance selection
  • Remove a machine type from an instance selection
  • Change the ranks of instance selections
  • Add an instance selection

The MIG applies the changes based on the instance selection names that you specify. Any instance selections that you don't specify remain unchanged. When you make changes to an instance selection, you must specify its full configuration when editing. If you don't specify the full configuration, the MIG will overwrite the unspecified parts of the instance selection. For example, if you want to change only a rank, specify the new rank along with the machine types set in that selection. To view the existing configuration, see View instance flexibility.

After you remove a machine type from the configuration, the existing VMs with the removed machine types continue to use them. If you want to change those VMs' machine types, you must update or recreate the specific VMs. For more information, see Update a VM's machine type to use the latest configuration.

To change the instance flexibility configuration in a MIG, select one of the following options:

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 change the instance flexibility.

  3. Click Edit.

  4. In the Instance selections section, click Edit instance selections.

  5. In the Instance selections window, click the Toggle icon of an instance selection to open the Edit instance selection view.

    When editing an instance selection, you can make the following changes:

    • Change the name and rank of the instance selection. To do this, edit the values in the Name and Rank fields.
    • Add a new machine type to the selection. To do this, click Add machine type.
    • Remove machine types. To do this, select the machine types, and then click Remove.
  6. Modify the selection as required and click Done.

  7. After you complete making the changes in the Instance selections window, click Done.

  8. Click Save to apply the changes.

gcloud

To edit an instance flexibility configuration, use the instance-groups managed update command.

  gcloud compute instance-groups managed update INSTANCE_GROUP_NAME \
      --region REGION \
      --instance-selection "name=INSTANCE_SELECTION_1,machine-type=MACHINE_TYPE_1,machine-type=MACHINE_TYPE_2,rank=RANK_1" \
      --instance-selection "name=INSTANCE_SELECTION_2,machine-type=MACHINE_TYPE_3,machine-type=MACHINE_TYPE_4,rank=RANK_2"

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG in which you want to check the instance flexibility configuration.
  • REGION: the region where the MIG is located.
  • INSTANCE_SELECTION: the name of the instance selection in which you want to make the changes. You must specify both MACHINE_TYPE and RANK. If you're not changing any of these, you must provide the existing values to retain them.

REST

To edit an instance flexibility configuration, make a PATCH request to the regionInstanceGroupManagers.patch method.

  PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME

  {
    "instanceFlexibilityPolicy": {
      "instanceSelections": {
        "INSTANCE_SELECTION": {
          "machineTypes": [
            "MACHINE_TYPE_1",
            "MACHINE_TYPE_2"
          ],
          "rank": RANK
        }
      }
    }
  }

Replace the following:

  • PROJECT_ID: your project ID.
  • REGION: the region where the MIG is located.
  • INSTANCE_GROUP_NAME: the name of the MIG in which you want to check the instance flexibility configuration.
  • INSTANCE_SELECTION: the name of the instance selection in which you want to make the changes. You must specify both MACHINE_TYPE and RANK. If you're not changing any of these, you must provide the existing values to retain them.

Remove instance flexibility configuration

You can remove all or specific instance selections in a MIG.

  • To remove all instance selections in a MIG, see Remove all instance selections. When you remove all instance selections, the MIG uses the machine type specified in the instance template to create new VMs in the group.

  • To remove individual instance selections by names, see Remove specific instance selections. This removes only specific instance selections and the MIG retains the other ones.

After removing instance selections, the existing VMs that use the machine types from the removed instance selections continue to use the same machine type. For the changes to take effect, you must update or recreate those VMs. For more information, see Update a VM's machine type to use the latest configuration.

Remove all instance selections

To remove all instance selections, select one of the following options:

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 change the instance flexibility.

  3. Click Edit.

  4. In the Instance selections section, click Edit instance selections.

  5. In the Instance selections window, click the Delete icon next to each instance selection.

  6. Click Done.

  7. Click Save.

gcloud

To remove all instance selections in a MIG, use the instance-groups managed update command:

  gcloud compute instance-groups managed update INSTANCE_GROUP_NAME \
      --region REGION \
      --remove-instance-selections-all

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG from which you want to remove all the instance selections.
  • REGION: the region where the MIG is located.

REST

To remove all instance selections in a MIG, make a PATCH request to the regionInstanceGroupManagers.patch method.

  PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME

  {
    "instanceFlexibilityPolicy": {
      "instanceSelections": null
    }
  }

Replace the following:

  • PROJECT_ID: your project ID.
  • REGION: the region where the MIG is located.
  • INSTANCE_GROUP_NAME: the name of the MIG from which you want to remove an instance selection.

Remove specific instance selections

To remove specific instance selections, select one of the following options:

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 change the instance flexibility.

  3. Click Edit.

  4. In the Instance selections section, click Edit instance selections.

  5. In the Instance selections window, click the Delete icon next to the instance selection that you want to remove.

  6. Click Done.

  7. Click Save.

gcloud

To remove specific instance selections in a MIG, use the instance-groups managed update command:

  gcloud compute instance-groups managed update INSTANCE_GROUP_NAME \
      --region REGION \
      --remove-instance-selections INSTANCE_SELECTION

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG from which you want to remove an instance selection.
  • REGION: the region where the MIG is located.
  • INSTANCE_SELECTION: the name of the instance selection which you want to remove. If there are multiple instance selections, provide a comma separated list of the names.

REST

To remove specific instance selections in a MIG, use the regionInstanceGroupManagers.patch method.

  PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers/INSTANCE_GROUP_NAME

  {
    "instanceFlexibilityPolicy": {
      "instanceSelections": {
        "INSTANCE_SELECTION": null
      }
    }
  }

Replace the following:

  • PROJECT_ID: your project ID.
  • REGION: the region where the MIG is located.
  • INSTANCE_GROUP_NAME: the name of the MIG from which you want to remove an instance selection.
  • INSTANCE_SELECTION: the name of the instance selection which you want to remove. If there are multiple instance selections, specify all of them. For example, "selection-1": null,"selection-2": null.

Update a VM's machine type to use the latest configuration

If any VMs in a MIG use a machine type that was removed from the instance flexibility configuration, then you must update or recreate the VM to update its machine type.

To update or recreate a VM, use one of the following options:

  • Update the VMs using the regionInstanceGroupManagers.applyUpdatesToInstances method. When using the applyUpdatesToInstances method, the mostDisruptiveAllowedAction field must be RESTART OR REPLACE.

  • Recreate the VMs using the regionInstanceGroupManagers.recreateInstances method.

  • Recreate the VMs by first deleting the VMs and then resizing the MIG to the required number of VMs.

What's next