Attaching a target group to a network load balancer
To attach a target group to a network load balancer:
- In the management console
, select the folder where you wish to attach a target group to a load balancer. - In the list of services, select Network Load Balancer.
- In the line of the load balancer to attach a target group to, click
and select Attach target group. - Select a target group or create a new one.
- Configure health check settings.
- Click Attach target group.
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.
-
View the description of the CLI command to attach a target group to a network load balancer:
yc load-balancer network-load-balancer attach-target-group --help
-
Find out the ID or name of the load balancer by getting a list of network load balancers in the folder.
-
Attach a target group to your load balancer by specifying the group ID and health check settings in the appropriate command parameters:
yc load-balancer network-load-balancer attach-target-group <load_balancer_name_or_ID> \ --target-group target-group-id=<target_group_ID>,` `healthcheck-name=<health_check_name>,` `healthcheck-interval=<health_check_interval>s,` `healthcheck-timeout=<response_timeout>s,` `healthcheck-unhealthythreshold=<number_of_failed_health_checks_for_Unhealthy_status>,` `healthcheck-healthythreshold=<number_of_successful_health_checks_for_Healthy_status>,` `healthcheck-tcp-port=<TCP_port>,` `healthcheck-http-port=<HTTP_port>,` `healthcheck-http-path=<URL>
Where:
-
--target-group
: Target group parameters and settings of its resource health checks:-
target-group-id
: Target group ID.To find out the ID, get a list of target groups in the folder.
-
healthcheck-name
: Resource health check name. -
healthcheck-interval
: Health check interval in seconds. The possible values are from1s
to60s
. The interval must be at least 1 second longer than the waiting time. -
healthcheck-timeout
: Response timeout in seconds. The possible values are from1s
to60s
. -
healthcheck-unhealthythreshold
: Number of failed checks after which no traffic will be routed to a virtual machine. The possible values are from2
to10
. -
healthcheck-healthythreshold
: Number of successful checks required to consider a virtual machine ready to receive traffic. The possible values are from2
to10
. -
healthcheck-tcp-port
: Port for health checks via TCP. The possible values are from1
to32,767
. -
healthcheck-http-port
: Port for health checks via HTTP. The possible values are from1
to32,767
. -
healthcheck-http-path
: URL to perform health checks via HTTP.
You cannot specify
healthcheck-tcp-port
andhealthcheck-http-port
at the same time.Warning
The
healthcheck-interval
andhealthcheck-timeout
parameter values must be in<time_in_seconds>s
format, e.g.,20s
. -
For more information about check parameters, see Resource health check.
-
-
Open the Terraform configuration file and add the
attached_target_group
section to the network load balancer description:resource "yandex_lb_network_load_balancer" "foo" { name = "<load_balancer_name>" ... attached_target_group { target_group_id = "<target_group_ID>" healthcheck { name = "<health_check_name>" http_options { port = <port_number> path = "<URL>" } } } ... }
Where:
name
: Name of the network load balancer.attached_target_group
: Description of the network load balancer's target group parameters:-
target_group_id
: Target group ID.To find out the ID, get a list of target groups in the folder.
-
healthcheck
: Health check parameters. Enter a name, a port number ranging from1
to32767
, and a path for health checks.
-
For more information about resources you can create with Terraform, see the 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 network load balancer.
-
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 attach a target group to a network load balancer, use the attachTargetGroup REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/AttachTargetGroup gRPC API call and provide the following in the request:
- Load balancer ID in the
networkLoadBalancerId
parameter. - Target group ID in the
attachedTargetGroup.targetGroupId
parameter. - Health check settings in the
attachedTargetGroup.healthChecks
parameter.
You can get the load balancer ID with a list of network load balancers in the folder and the target group ID with a list of folder target groups.