Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Network Load Balancer
  • Getting started
    • All guides
      • Information about existing target groups
      • Creating a target group
      • Attaching a target group to a load balancer
      • Detaching a target group from a load balancer
      • Deleting a target group
    • Viewing operations with resources
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • FAQ
  1. Step-by-step guides
  2. Target groups
  3. Attaching a target group to a load balancer

Attaching a target group to a network load balancer

Written by
Yandex Cloud
Updated at May 13, 2025
Management console
CLI
Terraform
API

To attach a target group to a network load balancer:

  1. In the management console, select the folder where you want to attach a target group to a load balancer.
  2. In the list of services, select Network Load Balancer.
  3. Next to the load balancer to which you want to attach a target group, click and select Attach target group.
  4. Select a target group or create a new one.
  5. Configure health check settings.
  6. Click Attach target group.

If you do not have the Yandex Cloud (CLI) command line interface 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.

  1. See the description of the CLI command for attaching a target group to a network load balancer:

    yc load-balancer network-load-balancer attach-target-group --help
    
  2. Find out the ID or name of the load balancer by getting a list of network load balancers in the folder.

  3. 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_checks_to_get_Unhealthy_status>,`
                     `healthcheck-healthythreshold=<number_of_successful_checks_to_get_Healthy_status>,`
                     `healthcheck-tcp-port=<TCP_port>,`
                     `healthcheck-http-port=<HTTP_port>,`
                     `healthcheck-http-path=<URL>
    

    Where:

    • --target-group: Target group parameters and health check settings:

      • target-group-id: Target group ID.

        To find out the ID, get a list of target groups in the folder.

      • healthcheck-name: Health check name.

      • healthcheck-interval: Health check interval in seconds. The possible values range from 1s to 60s. The interval must be at least 1 second longer than the response timeout.

      • healthcheck-timeout: Response timeout in seconds. The possible values range from 1s to 60s.

      • healthcheck-unhealthythreshold: Number of failed checks before traffic is no longer routed to the VM. The possible values range from 2 to 10.

      • healthcheck-healthythreshold: Number of successful checks required to consider the VM ready to receive traffic. The possible values range from 2 to 10.

      • healthcheck-tcp-port: Port for TCP health checks. The possible values range from 1 to 32,767.

      • healthcheck-http-port: Port for HTTP health checks. The possible values range from 1 to 32,767.

      • healthcheck-http-path: URL for HTTP health checks.

      You cannot specify both healthcheck-tcp-port and healthcheck-http-port at the same time.

      Warning

      Use the <time_in_seconds>s format, e.g., 20s, for the healthcheck-interval and healthcheck-timeout values.

    For more information about health check settings, see Resource health check.

  1. 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 settings:
      • target_group_id: Target group ID.

        To find out the ID, get a list of target groups in the folder.

      • healthcheck: Health check settings. Specify a name, a port number ranging from 1 to 32767, and a path for health checks.

    For more information about the resources you can create with Terraform, see this article.

  2. Make sure the settings are correct.

    1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.

    2. Run this command:

      terraform validate
      

      Terraform will show any errors found in your configuration files.

  3. Create a network load balancer.

    1. 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.

    2. If everything looks correct, apply the changes:

      1. Run this command:

        terraform apply
        
      2. Confirm updating the resources.

      3. 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, providing the following in your 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 the list of network load balancers in the folder and the target group ID with the list of target groups in the folder.

Was the article helpful?

Previous
Creating a target group
Next
Detaching a target group from a load balancer
Yandex project
© 2025 Yandex.Cloud LLC