Change or remove instance flexibility configuration


This document describes how to make changes or remove instance flexibility in a managed instance group (MIG) by editing the instance flexibility policy.

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:

    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.

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 an unused machine type from an instance selection
  • Change the ranks of instance selections
  • Add an instance selection to an instance flexibility policy

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 editing a configuration, the following rules apply:

  • If you make a change 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 the instance flexibility configuration.

  • If you want to remove a machine type from an instance selection, you must delete any virtual machine (VM) instances in the MIG that use that machine type. To view the machine type of each VM in a MIG, see View the machine types used by each VM.

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

gcloud

To edit an instance flexibility configuration, use the beta update command.

  gcloud beta 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 beta regionInstanceGroupManagers.patch method.

  PATCH https://compute.googleapis.com/compute/beta/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 a MIG's instance flexibility configuration, see Remove all instance selections. This removes all VMs from the MIG and the MIG starts using a single machine type that is defined in the instance template.

  • 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.

Remove all instance selections

When removing all instance selections from a MIG, you must delete all VMs in the group by setting the target size to 0. After you remove all the instance selections, you can set the target size back to the required number of VMs in the group. The MIG then uses a single machine type that is defined in the instance template to create the VMs.

gcloud

To remove instance flexibility policy in a MIG, use the beta instance-groups managed update command:

  gcloud beta compute instance-groups managed update INSTANCE_GROUP_NAME \
      --region REGION \
      --size 0 \
      --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 instance flexibility policy in a MIG, make a PATCH request to the beta regionInstanceGroupManagers.patch method.

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

  {
    "targetSize": 0,
    "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

Before removing an instance selection, you must make sure that the VMs in the MIG don't use the machine types from that selection. You can check the machine types used by each VM. If any VM uses the machine types from the selection, delete those VMs first.

gcloud

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

  gcloud beta 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 beta regionInstanceGroupManagers.patch method.

  PATCH https://compute.googleapis.com/compute/beta/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.

What's next