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.

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.

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 making changes in the instance flexibility configuration, if you want the existing VMs to use the latest changes, you must delete those VMs and resize the MIG to the required number of VMs. Otherwise, the existing VMs continue to use their current machine types.

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.

Remove all instance selections

After you remove all instance selections, existing VMs that are using the machine types from the removed instance selections continue to use the same machine type. If you want those VMs to use the machine type specified in the instance template, you must delete those VMs and resize the MIG to the required number of VMs.

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

After you remove a specific instance selection, existing VMs that are using the machine types from the removed instance selection continue to use the same machine type. If you want those VMs to use the machine type specified in available instance selections, you must delete those VMs and resize the MIG to the required number of VMs.

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.

What's next