Create a MIG with multiple machine types

This document describes how to create a managed instance group (MIG) with instance flexibility, which lets you specify multiple machine types in the MIG.

Instance flexibility helps to improve resource obtainability, particularly for applications that can operate on different machine types and that require large-scale capacity or hardware with high demand. For more information, see About instance flexibility.

You can also read about other basic scenarios for creating a MIG.

Before you begin

Create a MIG with multiple machine types

Console

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

    Go to Instance groups

  2. Click Create instance group.

  3. In the Name field, enter a name for the MIG.

  4. In the Instance template list, select the instance template that you want to use for the MIG.

  5. In the Number of instances field, specify the number of VMs that you want in the group.

  6. In the Instance selections section, click Add selections.

    The Instance selections window opens.

    1. In the New instance selection section, do the following:

      1. In the Name field, enter a name for the instance selection. Because you're creating a single instance selection in this example, you can keep the default value for the Rank field.

      2. Repeat the following steps for each machine type that you want to add to the instance selection.

        1. Click Add machine type.

        2. In the Add machine type pane, select the Series of the machine type that you want to add.

        3. In the Machine type list, select the machine type.

        4. Click Done.

          If a selected machine type is not compatible with the disk or CPU platform configuration in the instance template, then the console displays a validation message, such as a message stating that the disk type cannot be used as a boot disk with the selected machine type. To resolve this, configure the overrides in the following steps.

      3. To override the minimum CPU platform specified in the instance template, do the following:

        1. Select the Override CPU platform for this selection checkbox.

        2. In the CPU platform list, select the platform that you want to use for the instance selection. Alternatively, to automatically select any compatible CPU platform for the selected machine types, select Automatic.

      4. To override the disk configuration specified in the instance template or to attach storage, do the following:

        1. Select the Override disks checkbox.

        2. To override the boot disk, in the Boot disk section, click Change, and follow the prompts.

        3. To attach storage, click Add new disk or Attach existing disk, and follow the prompts.

      5. In the New instance selection section, after you complete adding the machine types and any overrides, click Done.

    2. In the Instance selections window, click Done.

  7. Leave the other fields in their default settings or modify as needed.

  8. Click Create.

gcloud

To create a regional MIG with multiple machine types, use the instance-groups managed create command as follows:

gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \
    --region REGION \
    --size TARGET_SIZE \
    --template INSTANCE_TEMPLATE_URL \
    --target-distribution-shape SHAPE \
    --instance-redistribution-type none \
    --instance-selection-machine-types MACHINE_TYPE,MACHINE_TYPE,...

Zonal MIGs don't support instance flexibility. However, if you want to create a MIG in a single zone, set the target distribution shape to any-single-zone. Furthermore, if you want a specific zone, use the any-single-zone distribution shape and include the --zones ZONE flag.

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG.
  • REGION: the region where you want to create the MIG.
  • TARGET_SIZE: the number of VMs you want the MIG to create and maintain.
  • INSTANCE_TEMPLATE_URL: the URL of the instance template that you want to use to create instances in the MIG. The URL can contain either the ID or name of the instance template. Specify one of the following values:
    • For a regional instance template: projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
    • For a global instance template: INSTANCE_TEMPLATE_ID
  • SHAPE: the target distribution shape. The value can be balanced, any, or any-single-zone.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG—for example, n1-standard-16,n2-standard-16,e2-standard-16.

Terraform

If you haven't already created an instance template, which specifies the VM properties that you want for each VM in your MIG, create an instance template.

To create a regional MIG with multiple machine types, use the google_compute_region_instance_group_manager resource.

resource "google_compute_region_instance_group_manager" "default" {
  name               = "flex-igm"
  base_instance_name = "tf-test-flex-igm"
  region             = "us-central1"

  target_size                      = 3
  distribution_policy_target_shape = "ANY_SINGLE_ZONE"

  version {
    instance_template = google_compute_instance_template.default.id
  }

  instance_flexibility_policy {
    instance_selections {
      name          = "default-instance-selection"
      machine_types = ["n1-standard-16", "n2-standard-16", "e2-standard-16"]
    }
  }

  update_policy {
    instance_redistribution_type = "NONE"
    type                         = "OPPORTUNISTIC"
    minimal_action               = "REPLACE"
    max_surge_fixed              = 0
    max_unavailable_fixed        = 6
  }
}

To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.

REST

To create a regional MIG with multiple machine types, make a POST request to the regionInstanceGroupManagers.insert method.

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

{
  "name": "INSTANCE_GROUP_NAME",
  "targetSize": TARGET_SIZE,
  "instanceTemplate": "INSTANCE_TEMPLATE_URL",
  "distributionPolicy": {
    "targetShape": "SHAPE"
  },
  "updatePolicy": {
    "instanceRedistributionType": "NONE"
  },
  "instanceFlexibilityPolicy": {
    "instanceSelections": {
      "INSTANCE_SELECTION": {
        "machineTypes": [
          "MACHINE_TYPE_1",
          "MACHINE_TYPE_2",
          ...
        ]
      }
    }
  }
}

Zonal MIGs don't support instance flexibility. However, if you want to create a MIG in a single zone, set the target distribution shape to ANY_SINGLE_ZONE. Furthermore, if you want a specific zone, use the ANY_SINGLE_ZONE distribution shape and include the distributionPolicy.zones[].zone field in the request.

Replace the following:

  • PROJECT_ID: your project ID.
  • REGION: the region where you want to create the MIG.
  • INSTANCE_GROUP_NAME: the name of the MIG.
  • TARGET_SIZE: the number of VMs you want the MIG to create and maintain.
  • INSTANCE_TEMPLATE_URL: the URL of the instance template that you want to use to create instances in the MIG. The URL can contain either the ID or name of the instance template. Specify one of the following values:
    • For a regional instance template: projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_ID
    • For a global instance template: INSTANCE_TEMPLATE_ID
  • SHAPE: the target distribution shape. The value can be BALANCED, ANY, or ANY_SINGLE_ZONE.
  • INSTANCE_SELECTION: the name for the list of machine types.
  • MACHINE_TYPE: the machine types that you want to configure in the MIG—for example, "n1-standard-16","n2-standard-16","e2-standard-16".

What's next