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.
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"] } } }
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 lower preferred machine type.
"instanceFlexibilityPolicy": { "instanceSelections": { "instance-selection-1": { "rank": 1, "machineTypes": ["c3-standard-8","n2-standard-8","c2-standard-8"] }, "instance-selection-2": { "rank": 2, "machineTypes": ["c3-standard-16","n2-standard-16","c2-standard-16"] } } }
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 Reservations of Compute Engine zonal resources.
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.
Limitations
Instance flexibility has the following limitations:
Instance flexibility is not supported in zonal MIGs. You can use a regional MIG with a single zone instead.
Instance flexibility does not support the following MIG features:
- Regional MIGs with target distributions shapes set to
EVEN
orANY
- Autoscaling
- Automatic updating of VM configuration and canary updates (two instance templates)
- Updates on repairs
- Suspending or stopping VMs
- Resize requests
- Create instances with specific names
- Regional MIGs with target distributions shapes set to
When using a MIG with Cloud Load Balancing, use machine types with similar performance—for example, the same vCPU count—to prevent over-utilization of smaller hardware and under-utilization of faster machines. Otherwise, load balancing might not work effectively when using machine types with different performance.
What's next?
- Learn more about different machine types.
- Add instance flexibility to a MIG.
- View the instance flexibility configuration in a MIG.