Create an instance in a placement group
Create an instance in a placement group.
If you don't have the Nebius Israel 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 a description of the CLI command to create a placement group:
yc compute placement-group create --help
-
Create a placement group:
yc compute placement-group create --spread-strategy --name my-group
Result:
id: fdvte50kv3nclagfknoc folder_id: aoeieef3k7ppari05ajo created_at: "2019-12-20T08:59:44Z" name: my-group spread_placement_strategy: {}
This command creates a placement group with the following characteristics:
- Named
my-group
. - Placement strategy
spread
.
- Named
-
View the description of the CLI command for creating a VM:
yc compute instance create --help
-
Create a virtual machine:
yc compute instance create --zone il1-a --name instance-in-group-1 --placement-group-name my-group
Result:
id: epdep2kq6dt5uekuhcrd ... placement_policy: placement_group_id: fd83bv4rnsna2sjkiq4s
This command creates a VM instance with the following characteristics:
- Named
instance-in-group-1
. - In the
il1-a
availability zone. - In the
my-group
placement group.
- Named
-
Check that the instance was created and added to the placement group:
yc compute placement-group list-instances --name my-group
Result:
+----------------------+---------------------+---------------+---------+-------------+-------------+ | ID | NAME | ZONE ID | STATUS | EXTERNAL IP | INTERNAL IP | +----------------------+---------------------+---------------+---------+-------------+-------------+ | epdep2kq6dt5uekuhcrd | instance-in-group-1 | il1-a | RUNNING | | 10.129.0.5 | +----------------------+---------------------+---------------+---------+-------------+-------------+
Use the create REST API method for the Instance resource or the InstanceService/Create gRPC API call.
With Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.
If you do not have Terraform yet, install it and configure the Nebius Israel provider.
To create a VM instance in a placement group:
-
In the configuration file, describe the parameters of the virtual machine pointing to
yandex_compute_placement_group
in theplacement_group_id
field. Theyandex_compute_instance
resource describe the virtual machine parameters.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
: ID of a placement group.For more information about the parameters of the
yandex_compute_instance
andyandex_compute_placement_group
resources 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 are 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 verify that the virtual machine has been created and added to the placement group from the management console
.