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 target group.
-
Enter the name of the target group. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
Select the VMs to add to the target group.
-
Click Create.
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.
-
See the description of the CLI command to create a target group:
yc load-balancer target-group create --help
-
Create a target group and add the appropriate VMs to it as targets by specifying the VM parameters 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 don't have Terraform, install it and configure the Yandex Cloud provider.
-
Describe the parameters of the target group resource in a configuration file:
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 = "<resource_internal_IP_address>" } target { subnet_id = "<subnet_ID>" address = "<resource_2_internal_IP_address>" } }
name
: Target group name.target
: Target resource description:subnet_id
: ID of the subnet the target objects are connected to. All target objects in the target group must reside within the same availability zone.address
: Resource internal IP address.
For more information about the
yandex_lb_target_group
resource parameters in Terraform, see the relevant provider documentation . -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Create a target group.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of 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.
Once the target group has been created, add targets that the load will be distributed across. To do this, use the addTargets REST API method for the TargetGroup resource or the TargetGroupService/AddTargets gRPC API call.