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
- Select a target group or create a new one.
- Configure health check settings.
- Click Attach target group.
If you don't 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
-
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 ID or name> \ --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 for health checks>
Where:
-
--target-group
: Target group parameters and settings of its resource health checks:target-group-id
: Target group ID.healthcheck-name
: Resource health check name.healthcheck-interval
: Health check interval in seconds.healthcheck-timeout
: Response timeout in seconds.healthcheck-unhealthythreshold
: Number of successful checks required to consider a VM instance ready to receive traffic.healthcheck-healthythreshold
: Number of failed checks after which no traffic will be routed to a VM instance.healthcheck-tcp-port
: Port for health checks via TCP. The acceptable values are from1
to32767
.healthcheck-http-port
: Port for health checks via HTTP. The acceptable values are from1
to32767
.healthcheck-http-path
: URL to perform health checks via HTTP.
You cannot specify
healthcheck-tcp-port
andhealthcheck-http-port
at the same time.Please note:
healthcheck-interval
andhealthcheck-timeout
parameter values must be in<time in seconds>s
format, e.g.,20s
.
You can get the load balancer ID and name with a list of network load balancers in the folder and the target group ID with a list of folder target groups.
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 = "<network load balancer name>" ... attached_target_group { target_group_id = "<target group ID>" healthcheck { name = "<health check name>" http_options { port = <port number> path = "<URL for health checks>" } } } ... }
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.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.