Instance template
When creating a group, you need to describe an instance template, which is the basic instance configuration used for deploying all instances in the group.
Both the template and policy description are provided to the CLI in a YAML file using the --file
flag when creating or updating an instance group. This is a convenient method to provide values that consist of multiple strings. For more information, see Creating a fixed-size instance group.
You can set variable values for the instance template. For more information, see Variables in an instance template.
Computing resources
When describing a template, you specify the computing resources to allocate to each instance, i.e., the number and guaranteed performance of processor cores (vCPUs) and the amount of RAM. You can choose the computing resources that are appropriate for the expected load. For more information, see vCPU performance levels.
You can also use a template to enable creating preemptible instances, which are cheaper than regular ones. Preemptible instances can only be autohealed if the computing resources in the availability zone allow for this. If the resources are insufficient, Instance Groups will resume autohealing as soon as the resources become available; this, however, may take a long time.
You can enable a software-accelerated network for group instances. This will transfer the processing of VM network traffic to additional compute cores.
Disks and file storages
Each instance must have at least one disk attached, which is a boot disk. Each boot disk is created automatically and attached to a single instance when creating an instance group. For more information, see Disks.
You can also attach additional disks to each instance. You can create an additional disk along with an instance group. You can create an empty disk or restore it from a snapshot or an image. You can only attach or detach additional disks when creating or updating a group. You can update secondary disks by updating YAML specification.
Alert
When you delete a VM, its disks are also deleted from the group. You can delete VMs during scaling and automatic recovery.
In addition to disks, you can also attach file storages to instances within a group. File storages allow configuring an instance to handle stateful workloads by saving the states of applications running on the instance to the storage independent of the instance group.
After attaching a file storage to a VM in the group, mount it on the VM's operating system. You can attach file storages using the CLI, Terraform, or API. For more information, see Creating an instance group connected to a file storage.
Network
When creating a group, you can:
- Set the network for the entire group.
- Set subnets for each instance in the group.
A service account used to perform operations in Instance Groups should have a role for accessing network and subnets where the instance group is located. For more information, see Access.
You can create a group without specifying any subnets for its instances if the availability zone selected for each instance contains exactly one subnet for the specified network.
Note
In the cloud network, there can be automatically created subnets, in addition to the ones, that you created. For example, the Cloud Functions, Serverless Containers, and API Gateway service subnets, or [reserved addresses[ for Managed Service for Kubernetes cluster pods and services.
You can also configure a public IP address for each instance. This allows the instance to connect to other services over the internet. For more information, see VM network interfaces.
You can specify the appropriate security groups in a template or configure them individually for each instance in the group.
Metadata
You can use a template to describe the metadata service parameters and the VM metadata for the instances in the group. For example, in the user-data
key, you can describe the system users to be added or the software installation scripts to be run when creating a new VM. Read more about the metadata supported by Compute Cloud in VM metadata.
Template description in a YAML file
A template describes the configuration of the base instance. It is defined in the instance_template
key in a YAML file.
Here is how a YAML file entry may look like:
...
instance_template:
platform_id: standard-v3
resources_spec:
memory: 2G
cores: 2
core_fraction: 20
boot_disk_spec:
mode: READ_WRITE
disk_spec:
image_id: jk9ib7ecsbrj********
type_id: network-hdd
size: 50G
preserve_after_instance_delete: false
secondary_disk_specs:
- name: disk-2
mode: READ_WRITE
disk_spec:
preserve_after_instance_delete: false
type_id: network-hdd
size: 21474836480
filesystem_specs:
- mode: READ_WRITE
device_name: sample-fs
filesystem_id: epdccsrlalon********
network_interface_specs:
- network_id: adv1rq7pmi05********
subnet_ids:
- u8zxv2v5f3rr********
primary_v4_address_spec: {
one_to_one_nat_spec: {
ip_version: IPV4
}
}
security_group_ids:
- enps0ar5s3ti********
network_settings:
type: SOFTWARE_ACCELERATED
placement_policy:
placement_group_id: rmppvhrgm77g********
service_account_id: ajegtlf2q28a********
metadata_options:
gce_http_endpoint: ENABLED
aws_v1_http_endpoint: DISABLED
gce_http_token: DISABLED
aws_v1_http_token: DISABLED
metadata:
user-data: |-
#cloud-config
write_files:
- path: /var/lib/cloud/scripts/per-boot/01-run-load-generator.sh
permissions: '0555'
content: |
#!/bin/bash
docker run -d --net=host -p 80:80 openresty/openresty:alpine
users:
- name: my-user
groups: sudo
shell: /bin/bash
sudo: 'ALL=(ALL) NOPASSWD:ALL'
ssh_authorized_keys:
- ssh-ed25519 AAAAB3...
...
By default, the disk size is specified in bytes. You can specify a different unit of measurement using the applicable suffix.
Suffix | Prefix and multiplier | Example |
---|---|---|
k |
kilo- (210) | 640k = 640 × 210 = 655360 |
m |
mega- (220) | 48m = 48 × 220 = 50331648 |
g |
giga- (230) | 10g = 10 × 230 = 10737418240 |
t |
tera- (240) | 4t = 4 × 240 = 4398046511104 |
p |
peta- (250) | 2p = 2 × 250 = 2251799813685248 |
Keys (the table lists keys that directly define the base instance configuration):
Key | Value |
---|---|
platform_id |
ID of the instance's hardware platform. |
resources_spec.memory |
Amount of RAM available to the instance, specified in bytes. The maximum value is 274877906944 (275 GB). |
resources_spec.cores |
Number of cores available to the instance. The value depends on the platform type. |
resources_spec.core_fraction |
Basic vCPU performance level. |
boot_disk_spec |
Boot disk parameters. |
boot_disk_spec.disk_spec.mode |
Disk access mode.– READ_ONLY : Read access.– READ_WRITE : Read and write access. |
boot_disk_spec.disk_spec.image_id |
ID of the image to create the VM from. |
boot_disk_spec.disk_spec.type_id |
ID of the disk type. To get a list of available disk types, use the diskTypes request. |
boot_disk_spec.disk_spec.size |
Size of the disk, specified in bytes. Acceptable values are in the range from 4194304 (4 MB) to 4398046511104 (4 TB). |
boot_disk_spec.preserve_after_instance_delete |
Option to preserve the disk on instance deletion.– true : Preserve the disk on instance deletion.– false : Delete the disk together with the instance. |
secondary_disk_specs |
(Optional) Secondary disks parameters. |
secondary_disk_specs.name |
(Optional) Secondary disk name. In the same specification, names should be assigned either to all secondary disks or none of them. For more information, see Updating secondary disks in an instance template. |
secondary_disk_specs.mode |
Disk access mode.– READ_ONLY : Read access.– READ_WRITE : Read and write access. |
secondary_disk_specs.disk_spec.preserve_after_instance_delete |
Option to preserve the disk on instance deletion.– true : Preserve the disk on instance deletion.– false : Delete the disk together with the instance. |
secondary_disk_specs.disk_spec.type_id |
ID of the disk type. To get a list of available disk types, use the diskTypes request. |
secondary_disk_specs.disk_spec.size |
Size of the disk, specified in bytes. Acceptable values are in the range from 4194304 (4 MB) to 4398046511104 (4 TB). |
filesystem_specs |
(Optional) File storage parameters. |
filesystem_specs.mode |
File storage access mode: – READ_ONLY : Read access.– READ_WRITE : Read and write access (default). |
filesystem_specs.device_name |
Device name for attaching the file storage to the VM, e.g., sample-fs . After attaching a file storage to a VM in the group, mount it on the VM's operating system. For more information, see Creating an instance group connected to a file storage. |
filesystem_specs.filesystem_id |
File storage ID. |
network_interface_specs.network_id |
Cloud network ID. |
network_interface_specs.subnet_ids |
IDs of cloud subnets. |
network_interface_specs.ip_version |
IP version for the public IP address. |
network_interface_specs.security_group_ids |
Security group IDs. |
network_settings.type |
(Optional) Network type.– SOFTWARE_ACCELERATED : Software-accelerated network.– STANDARD : Standard network (default). |
metadata_options |
(Optional) Metadata service parameters. |
metadata_options.gce_http_endpoint |
(Optional) Access metadata using the Google Compute Engine format.– enabled : Enabled.– disabled : Disabled. |
metadata_options.aws_v1_http_endpoint |
(Optional) Access metadata using the AWS format (IMDSv1).– enabled : Enabled.– disabled : Disabled. |
metadata_options.gce_http_token |
(Optional) Access Identity and Access Management credentials using the Google Compute Engine format.– enabled : Enabled.– disabled : Disabled. |
metadata_options.aws_v1_http_token |
(Optional) Access Identity and Access Management credentials using the AWS format (IMDSv1).– enabled : Enabled.– disabled : Disabled. |
metadata |
(Optional) Metadata for a template instance. For more information, see VM metadata. |
metadata.user-data |
Additional settings for instance initialization. In the example, the settings are described for the cloud-init program. |
placement_policy |
(Optional) VM placement group parameters. |
placement_policy.placement_group_id |
Placement group ID. VM instances will reside in data center server racks depending on the selected placement strategy:– spread placement strategy ensures that each VM instance resides in a separate server rack in one of the availability zones.– partition placement strategy evenly distributes VM instances among the group's partitions and ensures that VM instances from different partitions reside in different server racks in one of the availability zones. |
service_account_id |
(Optional) Service account attached to the VMs in the group that enables them to use cloud resources. Using a service account enables flexible configuration of access permissions for resources.For more granular management of access permissions, attach different service accounts with different permissions to the instance group and VMs in the group. |
For information about the technical restrictions of Instance Groups, see Quotas and limits in Compute Cloud.