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.

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, 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 as follows.

    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

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.

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:

Console

To create an instance template configured to create resize requests in a MIG, do the following:

  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 (default).

    • To create a regional instance template, select Regional, and then select the region where you want 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:

gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
    --image-project=IMAGE_PROJECT \
    --image-family=IMAGE \
    --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 or IMAGE_FAMILY: specify one of the following:

    • IMAGE: a specific version of the OS image; for example, debian-10-buster-v20200309.

    • IMAGE_FAMILY: an image family. This specifies the most recent, non-deprecated OS image. For example, if you specify debian-10, the latest version in the Debian 10 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 --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 the instanceTemplates.insert method. In the request body, do the following:

  • Set the scheduling.onHostMaintenance field to TERMINATE.

  • Set the reservationAffinity.consumeReservationType field to NO_RESERVATION.

For example, make a POST request as follows:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/instanceTemplates

{
  "name": "INSTANCE_TEMPLATE_NAME",
  "properties": {
    "disks": [
      {
        "boot": true,
        "mode": "READ_WRITE",
        "type": "PERSISTENT",
        "initializeParams": {
          "sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
        }
      }
    ],
    "machineType": "MACHINE_TYPE",
    "networkInterfaces": [
      {
        "accessConfigs": [
          {
            "name": "external-IP",
            "type": "ONE_TO_ONE_NAT"
          }
        ],
        "network": "global/networks/default"
      }
    ],
    "reservationAffinity": {
      "consumeReservationType": "NO_RESERVATION"
    },
    "scheduling": {
      "onHostMaintenance": "TERMINATE"
    }
  }
}

Replace the following:

  • PROJECT_ID: the ID of the project where to create the instance template in.

  • 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 or IMAGE_FAMILY: specify one of the following:

    • IMAGE: a specific version of the OS image; for example, debian-10-buster-v20200309.

    • IMAGE_FAMILY: an image family. This specifies the most recent, non-deprecated OS image. For example, if you specify debian-10, the latest version in the Debian 10 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:

Console

To create a zonal MIG configured for creating resize requests, do the following:

  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 you created in the previous section. If you select a regional instance template, the Region list is set to the region of the instance template.

  5. In the Location section, do the following:

    1. Select Single zone (default).

    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.

gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \
    --template=INSTANCE_TEMPLATE_NAME \
    --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_NAME: the name of the instance template you created in the previous section.

  • ZONE: the zone where to create the MIG.

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.

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

{
  "versions": [
    {
      "instanceTemplate": "global/instanceTemplates/INSTANCE_TEMPLATE_NAME"
    }
  ],
  "name": "INSTANCE_GROUP_NAME",
  "targetSize": 0,
  "instanceLifecyclePolicy": {
    "defaultActionOnFailure": "DO_NOTHING"
  }
}

Replace the following:

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

  • ZONE: the zone where to create the MIG.

  • INSTANCE_TEMPLATE_NAME: the name of the instance template you created in the previous section.

  • INSTANCE_GROUP_NAME: the name of the MIG to create.

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

Console

To create a resize request in a MIG, do the following:

  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 beta instance-groups managed resize-requests create command.

gcloud beta 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 beta.instanceGroupManagerResizeRequests.insert method.

POST https://compute.googleapis.com/compute/beta/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).

What's next