This document describes how to create a managed instance group (MIG) with instance flexibility that 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 an instance template, which is required in order to create a managed instance group.
-
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
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- 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.
-
Create a MIG with multiple machine types
gcloud
To create a regional MIG with multiple machine types, use the
beta instance-groups managed create
command
as follows:
gcloud beta compute instance-groups managed create INSTANCE_GROUP_NAME \ --region REGION \ --size TARGET_SIZE \ --template INSTANCE_TEMPLATE \ --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
: the name of the instance template.SHAPE
: the target distribution shape. The value can bebalanced
orany-single-zone
. The other target distribution shapes are not supported.MACHINE_TYPE
: the machine types that you want to configure in the MIG—for example,n1-standard-16,n2-standard-16,e2-standard-16
.
REST
To create a regional MIG with multiple machine types, make a POST
request to
the
beta regionInstanceGroupManagers.insert
method.
POST https://compute.googleapis.com/compute/beta/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.SHAPE
: the target distribution shape. The value can beBALANCED
orANY_SINGLE_ZONE
. The other target distribution shapes are not supported.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"
.
If you want to configure instance flexibility with preference for some machine types, you can use ranks. For more information, see Create a MIG with multiple machine types and preference.