About instance flexibility in MIGs


Instance flexibility in managed instance groups (MIGs) lets you specify multiple machine types for the virtual machine (VM) instances in the group, rather than being limited to a single machine type. If a machine type is unavailable, the MIG can automatically select another compatible type from your list based on the current resource availability. This 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.

This document describes how instance flexibility works in a MIG and its limitations. To know how to configure a MIG to use instance flexibility, see Add instance flexibility.

Instance flexibility

A MIG creates all its VMs based on the instance template that you select. The instance template specifies the machine type to use for each VM. With instance flexibility, you can list all the machine types that are compatible with your application.

The following image compares a MIG that uses a single machine type with a MIG that uses instance flexibility. As depicted in the image, a MIG with a single machine type creates identical VMs based on an instance template, whereas a MIG with instance flexibility can create VMs with different machine types and sizes.

Comparison of a MIG that uses a single machine type with a MIG that uses instance flexibility

How instance flexibility works

By default, a MIG creates all VMs using a single machine type from the instance template. You can set multiple machine types in a MIG by configuring an instance selection (instanceSelections) in the instance flexibility policy (instanceFlexibilityPolicy).

If your workload can operate on a number of different machine types, you can configure just a list of all machine types compatible with your application in a single instanceSelection as follows:

  "instanceFlexibilityPolicy": {
    "instanceSelections": {
      "instance-selection-1": {
        "machineTypes": ["c3-standard-8","n2-standard-8","c2-standard-8"]
      }
    }
  }
  

The machine types within an instance selection have equal preference. If you want a MIG to choose machine types in a specific order, you can configure multiple instance selections, each with a list of machine types and a rank to define preference. A lower value of rank means higher preference. The MIG attempts to create its VMs using machine types with a higher preference. If these preferred machine types are not available, the MIG uses a machine type with a lower preference.

  "instanceFlexibilityPolicy": {
    "instanceSelections": {
      "most-preferred": {
        "rank": 1,
        "machineTypes": ["c3-standard-16","n2-standard-16","c2-standard-16"]
      },
      "least-preferred": {
        "rank": 2,
        "machineTypes": ["c3-standard-8","n2-standard-8","c2-standard-8"]
      }
    }
  }
  

Your application needs to be ready to run on any of listed machine types as the availability of hardware changes over time and specific hardware is not assured unless you use reservations.

How a MIG selects machine types

When you configure multiple machine types, the MIG selects a machine type based on current resource availability and prioritizes unused reservations. If you've configured ranks, the MIG first considers your preference order. Within a ranked instance selection, the MIG then checks resource availability, followed by reservations.

The zones in the MIG's region might also impact the machine type selection because resource availability varies across zones. For more information, see the following section about how a MIG selects zones.

How a MIG selects zones

You can configure instance flexibility in a regional MIG that has either a BALANCED or ANY_SINGLE_ZONE target distribution shape. With instance flexibility, when a regional MIG creates a VM, it selects a zone depending on the selected target distribution shape as follows:

  • BALANCED: The MIG selects a zone with available resources that can balance the VM distribution across zones as evenly as possible. Within a selected zone, the MIG prioritizes machine types based on ranks, if configured, and available reservations.

  • ANY_SINGLE_ZONE: The MIG selects a zone which has the most machine types based on the ranks, if configured, and where the MIG can create most VMs out of unused reservations.

For more information about how a target distribution shape works, see Regional MIG target distribution shape.

Instance flexibility and reservations

You can use instance flexibility with reservations. A MIG uses reservations based on the reservationAffinity field that you set in the instance template.

When there are multiple machine types in an instance selection, the MIG selects the machine type with unused reservation first. If you want to change the order in which the MIG selects machine types, you can configure multiple instance selections and specify your preference using ranks. The MIG then first follows the preference order and then considers reservations within an instance selection.

For more information about reservations, see Choose a reservation type.

Instance flexibility and Spot VMs

If your MIG with instance flexibility uses Spot VMs, then the MIG automatically selects a machine type with the lowest observed preemption rate to ensure least disruption for your workload. If you want to override this behavior, you can configure multiple instance selections and specify your preference using ranks. The MIG then first follows the preference order and then considers the Spot VMs reliability within an instance selection.

For more information about Spot VMs, see Spot VMs in a managed instance group.

Instance flexibility and VM repairs

By default, if a VM in a MIG fails, the MIG repairs the VM by recreating it using the same configuration, including the machine type. If you configure instance flexibility and the original machine type of the failed VM is temporarily unavailable, the MIG selects another machine type based on the specified instance selection.

For more information about repairs, see About repairing VMs for high availability.

Use cases

The following sections describe some use cases of instance flexibility in MIGs.

Optimize costs

A MIG can automatically provision the most cost-effective instances for your infrastructure when you configure the instance flexibility settings of your MIG as follows:

  • Machine types: Select the machine types that offer the preferred cost-performance ratio for your workload. You don't need to specify all the available sizes of each machine type; specify only the sizes that are most cost-optimal for your needs.

  • Rank: Assign ranks to instance selections according to your cost preferences, with the lowest-cost machine type as most preferred. This helps to ensure that you obtain the lowest-cost machine type based on availability.

  • Location: When creating the MIG, select all zones and the BALANCED target distribution shape. This increases the chances of obtaining the lowest-cost machine types in zones where they are available.

Based on your instance flexibility settings, the MIG automatically provisions the best possible combination of available machine types to meet your cost criteria and the total capacity requested. This ensures the lowest possible cost at a given time.

Improve obtainability

You can configure MIG instance flexibility to improve obtainability. To do so, select as many machine types as possible that are compatible with your application within the same rank. You can further increase the chance of obtaining the resources by choosing all zones when creating your MIG and using the BALANCED target distribution shape, which prioritizes zones where resources are available. Based on the selected machine types and the BALANCED shape, the MIG finds capacity where it is most available.

To maximize the chances of acquiring Spot VMs and to reduce the chances of preemption, Google recommends you include a wide range of machine types within the same rank. This widens the MIG's search for available capacity, leading to the best possible outcomes with the spot provisioning model.

Maximize performance

You can configure MIG instance flexibility to maximize performance. To do so, select machine families and sizes that best serve your workload. Then rank the machine types based on performance, from highest to lowest, using the most preferred size within each family. Based on the ranking and the machine types, the MIG selects the highest-performing machines from all available resources.

Limitations

Instance flexibility has the following limitations:

What's next?