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. To learn more about resize requests, see About resize requests in a MIG.

Creating a MIG resize request helps you obtain highly-demanded resources, like GPUs, and optimize costs by creating the exact number of VMs all at once. To create a MIG resize request that can use the features and services available from Cluster Director, see Create a MIG and a resize request in the AI Hypercomputer documentation.

Before you begin

  • 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. After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    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.

      After installing the Google Cloud CLI, initialize it by running the following command:

      gcloud init

      If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

    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 MIG resize requests, 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 MIG resize requests. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create MIG resize requests:

  • To create an instance template: compute.instanceTemplates.create on the project
  • To create a zonal MIG: compute.instanceGroupManagers.create on the project
  • To create a MIG resize request: 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 a MIG resize requests, you must configure an instance template and the MIG as described in the following sections.

Create an instance template

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

To create an instance template configured to create MIG resize requests, 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. The Create an instance template page opens.

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

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

    1. Click the GPUs tab.

    2. In the GPU type list, select a GPU type. You can only select NVIDIA H200 141GB and later types if you use the instance template in zonal MIGs.

    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, then select Enable Virtual Workstation (NVIDIA GRID).

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

  6. In the Provisioning model section, do the following:

    1. In the VM provisioning model list, select Flex-start.

    2. To set a run duration for the VMs created through the instance template, in the Enter number of hours field, enter the number of hours. The value must be between one hour (1) and seven days (168).

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

  8. Click Create.

gcloud

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

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

  • The --instance-termination-action flag set to DELETE.

  • The --max-run-duration flag.

  • The --provisioning-model flag set to FLEX_START.

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

The following command creates a regional instance template. To create a global instance template, use the same command without the --instance-template-region flag.

gcloud beta 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 \
    --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. 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.

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

  • MACHINE_TYPE: a GPU machine type. Ensure the following:

    • You can only specify an A4 or A3 Ultra machine type for zonal MIGs.

    • If you specify an N1 machine type, then include the --accelerator flag 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 by d, h, m, and s respectively. For example, specify 30m for 30 minutes or 1d2h3m4s for 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 configured to create resize requests in a MIG, make a POST request to one of the following methods:

In the request body, include the following fields:

  • The scheduling.onHostMaintenance field set to TERMINATE.

  • The scheduling.instanceTerminationAction field set to DELETE.

  • The scheduling.maxRunDuration field.

  • The scheduling.provisioningModel field set to FLEX_START.

  • The reservationAffinity.consumeReservationType field set to NO_RESERVATION.

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

POST https://compute.googleapis.com/compute/beta/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. 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 GPU machine type. Ensure the following:

    • You can only specify an A4 or A3 Ultra machine type for zonal MIGs.

    • If you specify an N1 machine type, then include the guestAccelerators field in the request body 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 between 600, which is 600 seconds (10 minutes), and 604800, which is 604,800 seconds (seven days).

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 MIG that is compatible with 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. Before you select an instance template, you must delete the autoscaling configuration and turn off repairs as follows:

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

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

  5. Go back to the Instance template field. 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 template's region.

  6. Do one of the following:

    • To create a resize request when you create the MIG, do the following:

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

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

      3. Optional: To specify a different run duration for the VMs than the one set in the instance template, in the Requested run duration field and Unit lists, specify a duration. The duration must be between one hour and seven days.

    • To create a resize request after you create the MIG, in the Number of instances field, enter 0.

  7. In the Location section, specify whether you want to create a zonal or a regional MIG as follows:

    1. To create a zonal MIG, select Single zone. Or, to create a regional MIG, select Multiple zones.

    2. Select the Region and Zones of the MIG.

    3. If you're creating a regional MIG, then do the following:

      1. In the Target distribution shape field, select Any single zone.

      2. In the dialog that appears, click Disable instance redistribution.

  8. Click Create.

gcloud

Use the instance-groups managed create command with the --default-action-on-vm-failure flag set to do_nothing. If you're creating a regional MIG, then you must also include the --target-distribution-shape flag set to any-single-zone, and the --instance-redistribution-type flag set to none.

  • To create a zonal MIG, run 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
    
  • To create a regional MIG, run the following command:

    gcloud compute instance-groups managed create INSTANCE_GROUP_NAME \
        --template=INSTANCE_TEMPLATE_URL \
        --size=0 \
        --region=REGION \
        --target-distribution-shape=any-single-zone \
        --instance-redistribution-type=none \
        --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. 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. 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.

  • REGION: the region in which to create the MIG.

REST

  • To create a zonal MIG, send a POST request using the instanceGroupManagers.insert method 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"
      }
    }
    
  • To create a regional MIG, send a POST request using the regionInstanceGroupManagers.insert method as follows:

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceGroupManagers
    
    {
      "versions": [
        {
          "instanceTemplate": "INSTANCE_TEMPLATE_URL"
        }
      ],
      "name": "INSTANCE_GROUP_NAME",
      "targetSize": 0,
      "distributionPolicy": {
        "targetShape": "ANY_SINGLE_ZONE"
      },
      "updatePolicy": {
        "instanceRedistributionType": "NONE"
      },
      "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 exists.

  • INSTANCE_TEMPLATE_URL: the partial URL of the instance template that you created in the previous section. 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. 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

  • ZONE: the zone in which to create the MIG.

  • REGION: the region in which to create the MIG.

  • INSTANCE_GROUP_NAME: the name of the MIG to create.

Create a resize request in a MIG

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

After you create a resize request and all your 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. To add VMs with specific names to the MIG through a resize request, use the gcloud CLI or REST API.

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 Edit resize requests.

  4. Click add 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. Optional: To specify a different run duration for the VMs than the one set in the instance template, in the Requested run duration and Unit fields, specify a duration. The duration must be between one hour and seven days.

  8. Click Create.

gcloud

Replace the following:

  • INSTANCE_GROUP_NAME: the name of the 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 one day, two hours, three minutes, and four seconds. The value must be between 10 minutes and seven days.

  • ZONE: the zone where the MIG exists.

  • REGION: the region where the MIG exists.

Optionally, you can do the following:

REST

In the request body, include the following:

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

Replace the following:

  • PROJECT_ID: the ID of the project where the specified MIG exists.

  • ZONE: the zone where the MIG exists.

  • REGION: the region where the MIG exists.

  • INSTANCE_GROUP_NAME: the name of the 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 (seven days).

Optionally, you can do the following:

What's next

Morty Proxy This is a proxified and sanitized view of the page, visit original site.