Creating a Network Load Balancer target group
To create a new target group:
-
In the management console
, select the folder where you want to create a target group. -
In the list of services, select Network Load Balancer.
-
In the left-hand panel, select
Target groups. -
Click Create a target group.
-
Enter a name for the target group. Follow these naming requirements:
- It must be from 2 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- It must start with a letter and cannot end with a hyphen.
-
Select the VMs to add to the target group.
-
Click Create.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for creating a target group:
yc load-balancer target-group create --help
-
Create a target group and add the appropriate VMs as targets by specifying their settings in one or more
--target
parameters:yc load-balancer target-group create <target_group_name> \ --target subnet-id=<subnet_ID>,` `address=<VM_internal_IP_address>
If you do not have Terraform yet, install it and configure its Yandex Cloud provider.
-
In the configuration file, describe the settings for the target in the target group.
Here is an example of the configuration file structure:
resource "yandex_lb_target_group" "foo" { name = "<target_group_name>" target { subnet_id = "<subnet_ID>" address = "<target_internal_IP_address>" } target { subnet_id = "<subnet_ID>" address = "<resource_2_internal_IP_address>" } }
name
: Target group name.target
: Target description:subnet_id
: ID of the subnet hosting the targets. All targets in the target group must reside within the same availability zone.address
: Target internal IP address.
For more information about
yandex_lb_target_group
settings, see this Terraform article . -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validate
Terraform will show any errors found in your configuration files.
-
-
Create a target group.
-
Run this command to view the planned changes:
terraform plan
If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply
-
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
To create a new target group, use the create REST API method for the TargetGroup resource or the TargetGroupService/Create gRPC API call.
After you create a target group, add targets for load distribution. To do this, use the addTargets REST API method for the TargetGroup resource or the TargetGroupService/AddTargets gRPC API call.