Create an instance in a placement group
Create a VM in a placement group.
You can work with placement groups with the partition placement strategy using the CLI and API.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI command to create a placement group:
yc compute placement-group create --help
-
Create a placement group in the default folder with one of the placement strategies:
-
yc compute placement-group create \ --spread-strategy \ --name <placement_group_name>
Where:
--spread-strategy
: Shows that the spread placement strategy is selected.--name
: Placement group name.
-
yc compute placement-group create \ --partitions <partition_count> \ --name <placement_group_name>
Where:
--partitions
: Shows that the partition placement strategy is selected with the number of partitions specified: from1
to5
.--name
: Placement group name.
-
-
View the description of the CLI command to create a VM:
yc compute instance create --help
-
Create a VM:
yc compute instance create \ --zone ru-central1-a \ --name instance-in-group-1 \ --placement-group-name my-group \ --placement-group-partition <partition_number>
Where:
-
--zone
: Availability zone for the VM. -
--name
: VM name. -
--placement-group-name
: Placement group name. -
--placement-group-partition
: Partition number in the placement group with the partition placement strategy.Note
If you do not specify the partition number when creating a VM in a partition placement group, the VM will be added to a random partition.
Result:
id: epdep2kq6dt5******** ... placement_policy: placement_group_id: fd83bv4rnsna********
-
-
Check the new instance and its placement group:
yc compute placement-group list-instances --name my-group
Where
--name
is the placement group name.Result:
+----------------------+---------------------+-------------------+---------+-------------+-------------+ | ID | NAME | ZONE ID | STATUS | EXTERNAL IP | INTERNAL IP | +----------------------+---------------------+-------------------+---------+-------------+-------------+ | epdep2kq6dt5******** | instance-in-group-1 | ru-central1-a | RUNNING | | 10.129.0.5 | +----------------------+---------------------+-------------------+---------+-------------+-------------+
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To create a VM instance in a placement group:
-
In the configuration file, describe the VM parameters indicating the
yandex_compute_placement_group
resource in theplacement_group_id
field. Theyandex_compute_instance
resource describes the VM parameters.Here is an example of the configuration file structure:
... resource "yandex_compute_instance" "vm-1" { name = "linux-vm" platform_id = "standard-v3" placement_policy { placement_group_id = "${yandex_compute_placement_group.group1.id}" } } resource "yandex_compute_placement_group" "group1" { name = "test-pg" } ...
Where
placement_group_id
is the placement group ID.For more information about the
yandex_compute_instance
andyandex_compute_placement_group
resource parameters in Terraform, see the provider documentation . -
In the command line, go to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.All the resources you need will then be created in the specified folder. You can check that the VM has been created and added to the placement group using the management console
.
Use the create REST API method for the Instance resource or the InstanceService/Create gRPC API call.