Create resize requests in a MIG


This document describes how to create resize requests in a managed instance group (MIG) of virtual machine (VM) instances that have attached GPUs.

Creating resize requests in a MIG helps you obtain highly-demanded resources, like GPUs, and optimize costs by creating the exact number of VMs all at once.

Before you begin

  • Review how resize requests work.
  • To make sure that you have sufficient GPU quota for the resources you're requesting, check your GPU quota.
  • 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

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. 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.

Required roles

To get the permissions that you need to create resize requests in a MIG, ask your administrator to grant you the Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to create resize requests in a MIG. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create resize requests in a MIG:

  • To create an instance template: compute.instanceTemplates.create on the project
  • To create a zonal MIG: compute.instanceGroupManagers.create on the project
  • To create resize requests in a MIG: compute.instanceGroupManagers.update on the project

You might also be able to get these permissions with custom roles or other predefined roles.

Prepare a MIG for resize requests

To create resize requests in a MIG, you must configure an instance template and the MIG as described in the following sections.

Create an instance template

If you want to create resize requests in a MIG, then the MIG must use an instance template with the following configurations:

To create an instance template configured to create resize requests in a MIG, select one of the following options:

Console

  1. In the Google Cloud console, go to the Instance templates page.

    Go to Instance templates

  2. Click Create instance template.

  3. In the Name field, enter a name for the instance template.

  4. In the Location section, select one of the following options:

    • To create a global instance template, select Global, if it isn't already selected.

    • To create a regional instance template, select Regional, and then select the region in which to create the instance template.

  5. In the Machine configuration section, do the following:

    1. Click the GPUs tab.

    2. In the GPU type list, select the GPU type.

    3. In the Number of GPUs list, select the number of GPUs.

    4. Optional: If your GPU model supports NVIDIA RTX Virtual Workstations (vWS) for graphics workloads, and you plan to run graphics-intensive workloads, select Enable Virtual Workstation (NVIDIA GRID).

    5. In the Machine type section, select a machine type.

  6. 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.

  7. Expand the Advanced options section, and then do the following:

    1. Expand the Management section.

    2. In the Reservations list, select Don't use.

  8. Click Create.

gcloud

To create an instance template configured to create resize requests in a MIG, use the instance-templates create command with the following flags:

  • The --maintenance-policy flag set to TERMINATE.

  • The --reservation-affinity flag set to none.

For example, use the following command to create 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 \
    --machine-type=MACHINE_TYPE \
    --maintenance-policy=TERMINATE \
    --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. This specifies the most recent, non-deprecated OS image. For example, if you specify 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.

    If you want to use a specific version of the OS image, such as debian-12-buster-v20240701, then replace the --image-family flag with the --image flag.

  • REGION: the region in which to create the instance template.

  • MACHINE_TYPE: a machine type that supports GPUs. If you specify an N1 machine type, then include the --accelerator flag to specify the number and type of GPUs to attach to your VMs.

REST

To create an instance template configured to create resize requests in a MIG, make a POST request to one of the following methods:

In the request body, do the following:

  • Include the scheduling.onHostMaintenance field, and set it to TERMINATE.

  • Include the reservationAffinity.consumeReservationType field, and set it to NO_RESERVATION.

For example, to create a regional instance template, make a POST 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": "NO_RESERVATION"
    },
    "scheduling": {
      "onHostMaintenance": "TERMINATE"
    }
  }
}

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. This specifies the most recent, non-deprecated OS image. For example, if you specify family/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: a machine type that supports GPUs. If you specify an N1 machine type, then include the guestAccelerators field in the request body to specify the number and type of GPUs to attach to your VMs.

For more information about creating an instance template, see Create instance templates.

Create or update a MIG

After creating the instance template as described in the previous section, use that instance template to create a MIG as follows, or update a MIG. Additionally, you must do the following to prepare the MIG for resize requests:

To create a zonal MIG configured for creating resize requests, select one of the following options:

Console

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

    Go to Instance groups

  2. Click Create instance group.

    The Create instance group page opens.

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

  4. In the Instance template list, select the instance template that you created in the previous section. If you select a regional instance template, then the Region list is set to the region of the instance template.

  5. In the Location section, do the following:

    1. Select Single zone, if it isn't already selected.

    2. Select the Region and Zone of the MIG.

  6. To delete the autoscaling configuration, do the following:

    1. In the Autoscaling section, click the Autoscaling mode list, and then click Delete autoscaling configuration.

    2. In the confirmation dialog, click Delete.

  7. To turn off repairs, in the VM instance lifecycle section, click the Default action on failure list, and then select No action.

  8. Do one of the following:

    • To create a resize request at this point, do the following:

      1. In the Number of instances field, enter the number of VMs that you want to create all at once.

        The number of instances field on the Create instance group page.

      2. Select the Use resize request to create VMs all at once checkbox.

      3. In the Requested run duration field and the Unit list, specify the run duration of the VMs. The duration must be between 1 hour and 7 days.

    • Otherwise, in the Number of instances field, enter 0. You can later add VMs in the group by creating resize requests.

  9. Click Create.

gcloud

To create a zonal MIG configured for creating resize requests, use the instance-groups managed create command with the --default-action-on-vm-failure flag set to do_nothing.

For example, to create a zonal MIG using a regional instance template, use the following command:

gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \
    --template=INSTANCE_TEMPLATE_URL \
    --size=0 \
    --zone=ZONE \
    --default-action-on-vm-failure=do_nothing

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the MIG to create.

  • INSTANCE_TEMPLATE_URL: the partial URL of the instance template that you created in the previous section. Specify one of the following values:

    • For a regional instance template: projects/PROJECT_ID/regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME

    • For a global instance template: INSTANCE_TEMPLATE_NAME

  • ZONE: the zone in which to create the MIG. If you want to use a regional instance template to create the MIG, then you can only create the MIG within the template's region.

REST

To create a zonal MIG configured for creating resize requests, make a POST request to the instanceGroupManagers.insert method. In the request body, include the defaultActionOnFailure field set to DO_NOTHING.

For example, to create a zonal MIG using a regional instance template, make a POST request as follows:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers

{
  "versions": [
    {
      "instanceTemplate": "INSTANCE_TEMPLATE_URL"
    }
  ],
  "name": "INSTANCE_GROUP_NAME",
  "targetSize": 0,
  "instanceLifecyclePolicy": {
    "defaultActionOnFailure": "DO_NOTHING"
  }
}

Replace the following:

  • PROJECT_ID: the ID of the project where the instance template that you created in the previous section is located.

  • ZONE: the zone in which to create the MIG. If you want to use a regional instance template to create the MIG, then you can only create the MIG within the template's region.

  • INSTANCE_TEMPLATE_URL: the partial URL of the instance template that you created in the previous section. Specify one of the following values:

    • For a regional instance template: regions/REGION/instanceTemplates/INSTANCE_TEMPLATE_NAME

    • For a global instance template: global/instanceTemplates/INSTANCE_TEMPLATE_NAME

  • INSTANCE_GROUP_NAME: the name of the MIG to create.

For more information about creating a zonal MIG, see Create a MIG in a single zone.

Create a resize request in a MIG

Before you create resize requests, make sure that you've prepared the MIG as described in the previous section.

After you create a resize request, the request is accepted, and all the requested resources become available, the MIG creates the requested number of VMs all at once. The VMs run until the MIG deletes them after the specified run duration ends, or until you delete them.

To create a resize request in a MIG, select one of the following options:

Console

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

    Go to Instance groups

  2. In the Name column, click the name of the MIG in which to create the resize request.

    The overview page of the MIG opens.

  3. In the Resize requests row, click Edit resize requests.

  4. Click New resize request.

    The New resize requests pane appears.

  5. In the Name field, enter the name of the resize request.

  6. In the Number of additional instances needed field, enter the number of VMs to add to the MIG all at once.

  7. In the Requested run duration and Unit fields, specify the duration you want the requested VMs to run. The duration must be between 1 hour and 7 days.

  8. Click Create.

gcloud

To create a resize request in a MIG, use the instance-groups managed resize-requests create command.

gcloud compute instance-groups managed resize-requests create INSTANCE_GROUP_NAME \
    --resize-request=RESIZE_REQUEST_NAME \
    --resize-by=COUNT \
    --requested-run-duration=RUN_DURATION \
    --zone=ZONE

Replace the following:

  • INSTANCE_GROUP_NAME: the name of an existing zonal MIG configured for creating resize requests in it.

  • RESIZE_REQUEST_NAME: the name of the resize request, which must be unique within the specified MIG. Otherwise, creating the resize request fails.

  • COUNT: the number of VMs to add to the MIG all at once.

  • RUN_DURATION: the duration you want the requested VMs to run. The value must be formatted as the number of days, hours, minutes, or seconds followed by d, h, m, and s respectively. For example, specify 30m for 30 minutes or 1d2h3m4s for 1 day, 2 hours, 3 minutes, and 4 seconds. The value must be between 10 minutes and 7 days.

  • ZONE: the zone where the MIG is located.

REST

To create a resize request in a MIG, make a POST request to the instanceGroupManagerResizeRequests.insert method.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instanceGroupManagers/INSTANCE_GROUP_NAME/resizeRequests

{
  "name": "RESIZE_REQUEST_NAME",
  "resizeBy": COUNT,
  "requestedRunDuration": {
    "seconds": "RUN_DURATION"
  }
}

Replace the following:

  • PROJECT_ID: the ID of the project where the specified MIG is located.

  • ZONE: the zone where the MIG is located.

  • INSTANCE_GROUP_NAME: the name of an existing zonal MIG configured for creating resize requests in it.

  • RESIZE_REQUEST_NAME: the name of the resize request, which must be unique within the specified MIG. Otherwise, creating the resize request fails.

  • COUNT: the number of VMs to add all at once to the MIG.

  • RUN_DURATION: the duration, in seconds, you want the requested VMs to run. The value must be between 600, which is 600 seconds (10 minutes), and 604800, which is 604,800 seconds (7 days).

After creating a resize request, you can view its status or troubleshoot it by viewing the resize request's details.

What's next