Adding a VM to a placement group
Add an existing VM to a placement group.
You can manage placement groups with partition placement using the CLI and API.
- In the management console
, select the folder the placement group belongs to. - From the list of services, select Compute Cloud.
- In the left-hand panel, select
Placement groups. - Navigate to the Virtual machine placement groups tab.
- Select the placement group to add a VM to.
- Go to the Virtual machines panel.
- In the top-right corner, click
Add VM. - In the window that opens, select the VM and click Add.
Note
You can only add a VM with the stopped status to a placement group.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
Create a VM:
yc compute instance create \ --zone ru-central1-a \ --name instance-in-group-2Where:
--zone: Availability zone for the VM.--name: VM name.
Result:
id: epdlv1pp5401******** ... -
View a list of VMs in the placement group:
yc compute placement-group list-instances \ --name my-groupWhere
--nameis 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 | +----------------------+---------------------+-------------------+---------+-------------+-------------+ -
Stop the VM by specifying its name in the command below:
yc compute instance stop instance-in-group-2Result:
id: epdlv1pp5401******** ... status: STOPPED -
Add the VM to the placement group:
yc compute instance update \ --name instance-in-group-2 \ --placement-group-name my-group \ --placement-group-partition <partition_number>Where:
-
--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 adding a VM to a partition placement group, the VM will be added to a random partition.
Result:
id: epdlv1pp5401******** ... placement_policy: placement_group_id: fd83bv4rnsna******** -
-
Check that the VM is now in the placement group:
yc compute placement-group list-instances \ --name my-groupWhere
--nameis 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 | | epdlv1pp5401******** | instance-in-group-2 | ru-central1-a | STOPPED | | 10.129.0.30 | +----------------------+---------------------+-------------------+---------+-------------+-------------+ -
Start the VM by specifying its name in the command below:
yc compute instance start instance-in-group-2Result:
id: epdlv1pp5401******** ... status: RUNNING
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To add an existing VM to a placement group:
-
To the configuration file of the existing VM, add the
placement_group_idfield indicating theyandex_compute_placement_groupplacement group resource.Here is an example of the configuration file structure:
... resource "yandex_compute_instance" "vm-1" { name = "my-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_idis the placement group ID.Note
If you do not specify the partition number when adding a VM to a partition placement group, the VM will be added to a random partition.
For more information about the resources you can create with 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 validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply -
Confirm the changes: type
yesinto the terminal and press Enter.This will create all the resources you need in the specified folder. You can check that the VM has been added to the placement group using the management console
.
Use the update REST API method for the Instance resource or the InstanceService/Update gRPC API call.