This document explains how to create virtual machine (VM) instances that are deployed on Hypercompute Cluster. For more information about creating VMs in bulk, see About bulk creation of VMs in the Compute Engine documentation.
After you request blocks of resources and Compute Engine provisions them, you can start consuming these blocks by creating VMs in bulk. This is useful for managing groups of VMs and incorporating your own workload scheduler.
To learn about other ways to create VMs or clusters, see the Overview page.
Before you begin
-
Select the tab for how you plan to use the samples on this page:
gcloud
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
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 VMs in bulk,
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 VMs in bulk. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create VMs in bulk:
-
compute.instances.create
on the project -
To use a custom image to create the VM:
compute.images.useReadOnly
on the image -
To use a snapshot to create the VM:
compute.snapshots.useReadOnly
on the snapshot -
To use an instance template to create the VM:
compute.instanceTemplates.useReadOnly
on the instance template -
To assign a legacy network to the VM:
compute.networks.use
on the project -
To specify a static IP address for the VM:
compute.addresses.use
on the project -
To assign an external IP address to the VM when using a legacy network:
compute.networks.useExternalIp
on the project -
To specify a subnet for your VM:
compute.subnetworks.use
on the project or on the chosen subnet -
To assign an external IP address to the VM when using a VPC network:
compute.subnetworks.useExternalIp
on the project or on the chosen subnet -
To set VM instance metadata for the VM:
compute.instances.setMetadata
on the project -
To set tags for the VM:
compute.instances.setTags
on the VM -
To set labels for the VM:
compute.instances.setLabels
on the VM -
To set a service account for the VM to use:
compute.instances.setServiceAccount
on the VM -
To create a new disk for the VM:
compute.disks.create
on the project -
To attach an existing disk in read-only or read-write mode:
compute.disks.use
on the disk -
To attach an existing disk in read-only mode:
compute.disks.useReadOnly
on the disk
You might also be able to get these permissions with custom roles or other predefined roles.
Prerequisites
Before creating VMs in bulk, complete the following steps if you haven't already:Create a reservation: to have the necessary resources for your VMs, you first need to reserve blocks of resources.
For instructions, see Request capacity.
Optional: Create a placement policy: to place your VMs in a single block or sub-block and minimize network latency, you can optionally use a compact placement policy. This is useful for workloads that require fast communication among VMs. However, if you need to place your VMs on a specific block to meet particular hardware or network requirements, skip this step and specify the block name when you create the instance template.
For instructions, see Create a compact placement policy.
Create a regional instance template: to specify the VM configuration, including whether to create your VMs in a specific block within the reservation.
For instructions, see Create a regional instance template.
Create VMs in bulk
Create VMs in bulk by using the instance template created in the prerequisites step.
To create VMs in bulk to use your reserved blocks of resources, select one of the following options:
gcloud
To create VMs in bulk, use the
gcloud beta compute instances bulk create
command.
For example, to create VMs in bulk in a single zone and specify a name pattern, run the following command:
gcloud beta compute instances bulk create \
--count=COUNT \
--name-pattern="NAME_PATTERN" \
--source-instance-template=INSTANCE_TEMPLATE_URL \
--zone=ZONE
Replace the following:
COUNT
: the number of VMs to create.NAME_PATTERN
: the name pattern for the VMs. To replace a sequence of numbers in a VM name, use a sequence of hash (#
) characters. For example, usingvm-#
for the name pattern generates VMs with names starting withvm-1
,vm-2
, and continuing up to the number of VMs specified byCOUNT
.INSTANCE_TEMPLATE_URL
: the URL of the instance template that you created in the prerequisite steps. 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 VMs in bulk.
REST
To create VMs in bulk, make a POST
request to the
beta instances.bulkInsert
method.
For example, to create VMs in bulk in a single zone and specify a name pattern for the VMs, make a request as follows:
POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/bulkInsert
{
"count": "COUNT",
"namePattern": "NAME_PATTERN",
"sourceInstanceTemplate": "INSTANCE_TEMPLATE_URL"
}
Replace the following:
PROJECT_ID
: the ID of the project in which to create VMs in bulk and where the regional instance template that you created in the prerequisite steps is located.ZONE
: the zone in which to create VMs in bulk.COUNT
: the number of VMs to create.NAME_PATTERN
: the name pattern for the VMs. To replace a sequence of numbers in a VM name, use a sequence of hash (#
) characters. For example, usingvm-#
for the name pattern generates VMs with names starting withvm-1
,vm-2
, and continuing up to the number of VMs specified byCOUNT
.INSTANCE_TEMPLATE_URL
: the URL of the instance template that you created in the prerequisite steps. 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
For more information about the configuration options when creating VMs in bulk, see Create VMs in bulk in the Compute Engine documentation.