Creating a VM in a placement group
Create a VM in a placement group.
You can manage placement groups with partition placement using the CLI and API.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for creating a placement group:
yc compute placement-group create --help
-
Create a placement group in the default folder with one of the following placement strategies:
-
yc compute placement-group create \ --spread-strategy \ --name <placement_group_name>
Where:
--spread-strategy
: Shows that spread placement is selected.--name
: Placement group name.
-
yc compute placement-group create \ --partitions <number_of_partitions> \ --name <placement_group_name>
Where:
--partitions
: Shows that partition placement is selected, indicating the number of partitions from1
to5
.--name
: Placement group name.
-
-
See the description of the CLI command for creating 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 VM 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 | +----------------------+---------------------+-------------------+---------+-------------+-------------+
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the documentation on the Terraform
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To create a VM in a placement group:
-
In the configuration file, define 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 relevant 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 their 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.