This document describes how to use bulk mode in a MIG to create all of the virtual machine (VM) instances that you require at the same time. Creating instances all at once ensures that the MIG creates instances only when all necessary resources are available.
To learn how bulk mode works, see About bulk creation of instances in a MIG.
Create an instance template
Bulk mode in MIGs is only supported with instance templates that specify either a reservation-bound or flex-start provisioning model. To use bulk mode, create an instance template using one of these provisioning model as described in the following sections. For more information about the provisioning models, see Compute Engine instances provisioning models.
Use the reservation-bound provisioning model
To create an instance template, select one of the following options:
Console
In the Google Cloud console, go to the Instance templates page.
Click Create instance template. The Create an instance template page opens.
In the Name field, enter a name for the instance template.
In the Location section, select one of the following options:
To create a regional instance template, select Regional (recommended), and then select the region in which to create the template.
To create a global instance template, select Global.
In the Machine configuration section, specify a machine type.
In the Provisioning model section, complete the following steps:
Expand VM provisioning model advanced settings.
In the On VM termination list, select Delete.
Optional: To change the default value boot disk type or image, in the Boot disk section, click Change. Then, follow the prompts to change the boot disk.
Expand the Advanced options section, and then do the following:
Expand the Management section.
In the Reservations section, select Choose a reservation, and then click Choose reservation. In the pane that appears, follow the prompts to select the reservation that you want to consume.
Click Create.
gcloud
To create an instance template, use the
instance-templates create command with the following flag settings:
The
--instance-termination-actionflag set toDELETE.The
--maintenance-policyflag set toTERMINATE.The
--provisioning-modelflag set toRESERVATION_BOUND.The
--reservation-affinityflag set tospecific.The
--reservationflag.
The following example command creates a regional instance template. If you
want to create a global instance template, then use the same command without
the --instance-template-region flag.
gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
--image-project=IMAGE_PROJECT \
--image-family=IMAGE_FAMILY \
--instance-termination-action=DELETE \
--instance-template-region=REGION \
--machine-type=MACHINE_TYPE \
--maintenance-policy=TERMINATE \
--provisioning-model=RESERVATION_BOUND \
--reservation-affinity=specific \
--reservation=RESERVATION_URL
Replace the following:
INSTANCE_TEMPLATE_NAME: the name of the instance template to create.IMAGE_PROJECT: the image project that contains the image; for example,debian-cloud. For more information about the supported image projects, see Public images.IMAGE_FAMILY: an image family. Specify an image family to use the most recent, non-deprecated OS image. For example, if you specifydebian-12, the latest version in the Debian 12 image family is used. For more information about using image families, see Image families best practices.REGION: the region in which to create the instance template.MACHINE_TYPE: the machine type that is specified in the reservation that you want to consume.RESERVATION_URL: the URL of the auto-created reservation for a future reservation in calendar mode that you want to consume. Specify one of the following values:If the auto-created reservation exists in your project:
RESERVATION_NAME.If the auto-created reservation exists in a different project:
projects/PROJECT_ID/reservations/RESERVATION_NAME.
REST
To create an instance template, make a POST request to one of the
following methods:
To create a regional instance template:
regionInstanceTemplates.insertmethodTo create a global instance template:
instanceTemplates.insertmethod
In the request body, include the following fields:
The
reservationAffinity.consumeReservationTypefield set toSPECIFIC_RESERVATION.The
reservationAffinity.keyfield set tocompute.googleapis.com/reservation-name.The
reservationAffinity.valuesfield set to the URL of the auto-created reservation.The
scheduling.instanceTerminationActionfield set toDELETE.The
scheduling.onHostMaintenancefield set toTERMINATE.The
scheduling.provisioningModelfield set toRESERVATION_BOUND.
For example, to create a regional instance template, make a request as follows:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates
{
"name": "INSTANCE_TEMPLATE_NAME",
"properties": {
"disks": [
{
"boot": true,
"initializeParams": {
"sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
}
}
],
"machineType": "MACHINE_TYPE",
"networkInterfaces": [
{
"network": "global/networks/default"
}
],
"reservationAffinity": {
"consumeReservationType": "SPECIFIC_RESERVATION",
"key": "compute.googleapis.com/reservation-name",
"values": [
"RESERVATION_URL"
]
},
"scheduling": {
"instanceTerminationAction": "DELETE",
"onHostMaintenance": "TERMINATE",
"provisioningModel": "RESERVATION_BOUND"
}
}
}
Replace the following:
PROJECT_ID: the ID of the project in which to create the instance template.REGION: the region in which to create the instance template.INSTANCE_TEMPLATE_NAME: the name of the instance template to create.IMAGE_PROJECT: the image project that contains the image; for example,debian-cloud. For more information about the supported image projects, see Public images.IMAGE: specify one of the following:A specific version of the OS image—for example,
debian-12-bookworm-v20240617.An image family, which must be formatted as
family/IMAGE_FAMILY. Specify an image family to use the most recent, non-deprecated OS image. For example, if you specifyfamily/debian-12, the latest version in the Debian 12 image family is used. For more information about using image families, see Image families best practices.
MACHINE_TYPE: the machine type that is specified in the reservation that you want to consume.RESERVATION_URL: the URL of the auto-created reservation for a future reservation in calendar mode that you want to consume. Specify one of the following values:If the auto-created reservation exists in your project:
RESERVATION_NAMEIf the auto-created reservation exists in a different project:
projects/PROJECT_ID/reservations/RESERVATION_NAME
For more information about creating an instance template, see Create instance templates.
Use the flex-start provisioning model
To create an instance template, select one of the following options:
Console
In the Google Cloud console, go to the Instance templates page.
Click Create instance template. The Create an instance template page opens.
In the Name field, enter a name for the instance template.
In the Location section, select one of the following options:
To create a regional instance template, select Regional (recommended), and then select the region in which to create the template.
To create a global instance template, select Global.
In the Machine configuration section, specify a machine type.
In the Provisioning model section, complete the following steps:
In the VM provisioning model field, select Flex-start.
Expand VM provisioning model advanced settings.
Select the Set a time limit for the VM checkbox.
To set a run duration for the VMs that are created by using the instance template, in the Enter number of hours field, enter the number of hours. The value must be between 36 seconds (
0.01) and seven days (168).
Optional: To change the default value boot disk type or image, in the Boot disk section, click Change. Then, follow the prompts to change the boot disk.
Click Create.
gcloud
To create an instance template, use the
instance-templates create command with the following flag settings:
The
--instance-termination-actionflag set toDELETE.The
--maintenance-policyflag set toTERMINATE.The
--max-run-durationflag.The
--provisioning-modelflag set toFLEX_START.The
--reservation-affinityflag set tonone.
The following example command creates a regional instance template. If you
want to create a global instance template, then use the same command without
the --instance-template-region flag.
gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
--image-project=IMAGE_PROJECT \
--image-family=IMAGE_FAMILY \
--instance-template-region=REGION \
--instance-termination-action=DELETE \
--machine-type=MACHINE_TYPE \
--maintenance-policy=TERMINATE \
--max-run-duration=RUN_DURATION \
--provisioning-model=FLEX_START \
--reservation-affinity=none
Replace the following:
INSTANCE_TEMPLATE_NAME: the name of the instance template to create.IMAGE_PROJECT: the image project that contains the image; for example,debian-cloud. For more information about the supported image projects, see Public images.IMAGE_FAMILY: an image family. Specify an image family to use the most recent, non-deprecated OS image. For example, if you specifydebian-12, the latest version in the Debian 12 image family is used. For more information about using image families, see Image families best practices.REGION: the region in which to create the instance template.MACHINE_TYPE: the machine type to use for the Flex-start VMs. If you specify an N1 machine type, then you must include the--acceleratorflag to define the number and type of GPUs to attach to your VMs.RUN_DURATION: the duration you want the requested VMs to run. You must format the value as the number of days, hours, minutes, or seconds followed byd,h,m, andsrespectively. For example, specify30mfor 30 minutes or1d2h3m4sfor one day, two hours, three minutes, and four seconds. The value must be between 10 minutes and seven days.
REST
To create an instance template, make a POST request to one of the
following methods:
To create a regional instance template:
regionInstanceTemplates.insertmethodTo create a global instance template:
instanceTemplates.insertmethod
In the request body, include the following fields:
The
reservationAffinity.consumeReservationTypefield set toNO_RESERVATION.The
scheduling.instanceTerminationActionfield set toDELETE.The
scheduling.maxRunDurationfield.The
scheduling.onHostMaintenancefield set toTERMINATE.The
scheduling.provisioningModelfield set toFLEX_START.
The following example request creates a regional instance template:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates
{
"name": "INSTANCE_TEMPLATE_NAME",
"properties": {
"disks": [
{
"boot": true,
"initializeParams": {
"sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
}
}
],
"machineType": "MACHINE_TYPE",
"networkInterfaces": [
{
"network": "global/networks/default"
}
],
"reservationAffinity": {
"consumeReservationType": "NO_RESERVATION"
},
"scheduling": {
"instanceTerminationAction": "DELETE",
"maxRunDuration": {
"seconds": RUN_DURATION
},
"onHostMaintenance": "TERMINATE",
"provisioningModel": "FLEX_START"
}
}
}
Replace the following:
PROJECT_ID: the ID of the project in which to create the instance template.REGION: the region in which to create the instance template.INSTANCE_TEMPLATE_NAME: the name of the instance template to create.IMAGE_PROJECT: the image project that contains the image; for example,debian-cloud. For more information about the supported image projects, see Public images.IMAGE: specify one of the following:A specific version of the OS image—for example,
debian-12-bookworm-v20240617.An image family, which must be formatted as
family/IMAGE_FAMILY. Specify an image family to use the most recent, non-deprecated OS image. For example, if you specifyfamily/debian-12, the latest version in the Debian 12 image family is used. For more information about using image families, see Image families best practices.
MACHINE_TYPE: the machine type to use for the VMs. If you specify an N1 machine type, then you must include theguestAcceleratorsfield to define the number and type of GPUs to attach to your VMs.RUN_DURATION: the duration, in seconds, you want the requested VMs to run. The value must be between600, which is 600 seconds (10 minutes), and604800, which is 604,800 seconds (seven days).
For more information about creating an instance template, see Create instance templates.
Create a MIG that uses bulk mode
To enable bulk creation of instances in a MIG, set the targetSizePolicy.mode
field to BULK in the MIG's configuration. When you use this bulk mode, the MIG
waits for full resource availability and then creates instances all at once.
Console
Go to the Instance groups page.
Click Create instance group. The Create instance group page opens.
In the Name field, enter a name for the MIG.
Before you select an instance template, you must do the following:
- If you use the flex-start provisioning model, then you must turn off
repairs as follows:
- In the VM instance lifecycle section, clear the Allow repair of VMs in an alternate zone checkbox.
- In the Default action on failure list, select No action.
- In the Location section, do the following:
- To create a zonal MIG, select Single zone.
- To create a regional MIG, select Multiple zones. In the Target distribution shape, select Any single zone. In the dialog that appears, select Disable instance redistribution.
- If you use the flex-start provisioning model, then you must turn off
repairs as follows:
Go back to the Instance template field. In the Instance template list, select the instance template that you created in the previous section.
In the Number of instances field, specify the number of instances that you want to create all at once.
Select the Obtain VMs all at once with bulk target size policy checkbox.
Click Create.
gcloud
To create a MIG that has bulk creation enabled, use the
gcloud compute instance-groups managed create command
with the --target-size-policy-mode flag set to bulk.
If you use the flex-start provisioning model, then you must turn off repairs
in the MIG by including the --default-action-on-vm-failure=do-nothing flag
in the following commands.
- To create a zonal MIG, run the following command:
gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \
--size=SIZE \
--target-size-policy-mode=bulk \
--template=INSTANCE_TEMPLATE_URL \
--zone=ZONE \
- To create a regional MIG, run the following command:
gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \
--size=SIZE \
--target-size-policy-mode=bulk \
--template=INSTANCE_TEMPLATE_URL \
--zones=LIST_OF_ZONES \
Replace the following:
INSTANCE_GROUP_NAME: the name of the MIG.SIZE: the number of instances in the MIG.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
- For a regional instance template:
ZONE: the zone where the MIG creates instances.LIST_OF_ZONES: a comma-separated list of zones where the regional MIG creates instances. For example,us-central1-a, us-central1-b, us-central1-c.
REST
To create a MIG that has bulk creation enabled, make a POST request as
follows. In the request body, set the targetSizePolicy.mode field to
bulk.
If you use the flex-start provisioning model, then you must turn off repairs
in the MIG by including the
"instanceLifecyclePolicy": {"defaultActionOnFailure": "DO_NOTHING"} field
in the following requests.
To create a zonal MIG, make a
POSTrequest to theinstanceGroupManagers.insertmethod.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers { "name": "INSTANCE_GROUP_NAME", "targetSize": SIZE, "targetSizePolicy": { "mode": "bulk" }, "versions": [ { "instanceTemplate": "INSTANCE_TEMPLATE_URL" } ] }To create a regional MIG, make a
POSTrequest to theregionInstanceGroupManagers.insertmethod.POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers { "name": "INSTANCE_GROUP_NAME", "targetSize": SIZE, "targetSizePolicy": { "mode": "bulk" }, "versions": [ { "instanceTemplate": "INSTANCE_TEMPLATE_URL" } ] }
Replace the following:
PROJECT_ID:the project ID.ZONE:the zone where the MIG creates instances.REGION:the region where the MIG creates instances.INSTANCE_GROUP_NAME:the name of the MIG.SIZE:the number of instances in the MIG.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
- For a regional instance template:
Add or delete instances
In a MIG that uses the bulk mode, you can add or remove instances by manually increasing or decreasing the target size of the MIG.
Add instances: When you increase the target size from zero, the MIG adds instances the same way as when creating a MIG. You can also create instances with specific names by using the
createInstancesmethod when there is no instance in the MIG. To create instances with specific names, see Creating instances with specific names in MIGs.Delete instances: When you decrease the target size to zero, the MIG deletes all existing instances in the group and cancels any creation operation that was in progress. You can remove instances by decreasing the target size to
0. To decrease to a non-zero size, the MIG must not have a bulk instance operation in progress (bulkInstanceOperation.inProgressmust befalse).
To add or remove instances from a MIG by changing the target size, see Manually setting the size of a MIG.
What's next
- Learn how to view or cancel bulk creation of instances in a MIG.
- Learn how to work with managed instances.
- View information about MIGs and managed instances