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 network load balancers
      • Creating a load balancer
      • Creating an internal load balancer
      • Stopping and starting a load balancer
      • Changing load balancer settings
      • Moving a VM to a target group in a new availability zone
      • Deleting a load balancer
      • Checking target health statuses
      • Adding a listener
      • Deleting a listener
    • Viewing operations with resources
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • FAQ

In this article:

  • Examples
  • Creating a network load balancer without a listener
  • Creating a network load balancer with a listener and attached target group
  1. Step-by-step guides
  2. Network load balancers
  3. Creating a load balancer

Creating a network load balancer

Written by
Yandex Cloud
Improved by
Danila N.
Updated at May 13, 2025
  • Examples
    • Creating a network load balancer without a listener
    • Creating a network load balancer with a listener and attached target group

Note

Before you create a network load balancer, make sure to create a target group for it.

You can only set the load balancer type (internal or external) when creating it and cannot change it later.

Management console
CLI
Terraform
API

To create a network load balancer:

  1. In the management console, select the folder where you need to create a load balancer.

  2. In the list of services, select Network Load Balancer.

  3. Click Create a network load balancer.

  4. Name the load balancer. 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.
  5. Assign a public IP address to the load balancer. You can have the IP address assigned automatically or select it from the list of reserved addresses.

  6. Under Listeners, add a listener:

    1. Click Add listener.

    2. In the window that opens, specify these listener settings:

      • Name.

      • Protocol: TCP or UDP.

        Note

        By default, the listener uses TCP. To use UDP, contact technical support.

      • Port where the listener will listen for incoming traffic. The possible values range from 1 to 32767.

      • Target port to which the load balancer will redirect traffic. The possible values range from 1 to 32767.

    3. Click Add.

  7. Under Target groups, add a target group:

    1. Click Add target group.

    2. Select a target group or create a new one:

      • In the Target group field, select Create target group.
      • In the window that opens, enter a target group name.
      • Add VMs to the target group.
      • Click Create.
    3. Optionally, under Health check, click Configure. In the window that opens, specify the resource health check settings:

      • Name.
      • Type: HTTP or TCP. For HTTP health checks, specify the URL in the Path field.
      • Port for health checks. The possible values range from 1 to 32767.
      • Timeout in sec: Response timeout in seconds. The possible values range from 1 to 60. The interval must be at least 1 second longer than the response timeout.
      • Interval in sec: Health check interval in seconds. The possible values range from 1 to 60.
      • Healthy threshold: Number of successful checks required to consider the VM ready to receive traffic.
      • Unhealthy threshold: Number of failed checks before traffic is no longer routed to the VM.
    4. Click Apply.

  8. Click Create.

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 creating a network load balancer:

    yc load-balancer network-load-balancer create --help
    
  2. To create a load balancer with a listener and a target group, run this command:

    yc load-balancer network-load-balancer create <load_balancer_name> \
       --listener name=<listener_name>,`
                 `port=<port>,`
                 `target-port=<target_port>,`
                 `protocol=<protocol>,`
                 `external-ip-version=<IP_address_version> \
       --target-group target-group-id=<target_group_ID>,`
                     `healthcheck-name=<health_check_name>,`
                     `healthcheck-interval=<health_check_interval>s,`
                     `healthcheck-timeout=<health_check_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:

    • --listener: Listener settings:
      • name: Listener name.
      • port: Port on which the load balancer will listen to incoming traffic. The possible values range from 1 to 32767.
      • target-port: Port to which the load balancer will redirect traffic. The possible values range from 1 to 32767.
      • protocol: Protocol the listener will use, tcp or udp.
      • external-address: External IP address of the listener.
      • external-ip-version: External IP address version, ipv4 or ipv6.
    • --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.

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

  1. Describe the network load balancer settings in the configuration file.

    Here is an example of the configuration file structure:

    resource "yandex_lb_network_load_balancer" "foo" {
      name = "<load_balancer_name>"
      deletion_protection = "<deletion_protection>"
      listener {
        name = "<listener_name>"
        port = <port_number>
        external_address_spec {
          ip_version = "<IP_address_version>"
        }
      }
      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.
    • deletion_protection: Deletion protection for the network load balancer. You cannot delete a load balancer with this option enabled. This does not apply to its listeners or target groups. The default value is false.
    • listener: Listener settings:
      • name: Listener name.
      • port: Port number (ranging from 1 to 32767) on which the load balancer will listen to incoming traffic.
      • external_address_spec: Specification of the listener for the external load balancer settings:
        • ip_version: External IP address specification. Specify the IP address version, ipv4 or ipv6. The default value is ipv4.
    • 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 yandex_lb_network_load_balancer settings in 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 create a new network load balancer, use the create REST API method for the NetworkLoadBalancer resource or the NetworkLoadBalancerService/Create gRPC API call.

ExamplesExamples

Creating a network load balancer without a listenerCreating a network load balancer without a listener

Create a network load balancer named test-load-balancer-1 without a listener and a target group.

CLI
Terraform
API

Run this command:

yc load-balancer network-load-balancer create test-load-balancer-1
  1. In the configuration file, describe the load balancer settings, skipping the listener and attached_target_group sections:

    resource "yandex_lb_network_load_balancer" "foo" {
      name = "test-load-balancer-1"
      deletion_protection = "true"
    }
    

    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.

Use the create API method, providing the following in the request body:

{
  "folderId": "<folder_ID>",
  "name": "test-load-balancer-1",
  "type": "EXTERNAL"
}

Creating a network load balancer with a listener and attached target groupCreating a network load balancer with a listener and attached target group

Create a network load balancer with a listener and attached target group with the following test settings:

  • Name: test-load-balancer-2
  • Listener settings:
    • Name: test-listener
    • Port: 80
    • Target port: 81
    • Protocol: TCP
    • IP address version: ipv4
  • Target group ID: enpu2l7q9kth********
  • Target group health check settings:
    • Name: http
    • Health check interval: 2 seconds
    • Response timeout: 1 second
    • Unhealthy threshold: 2
    • Healthy threshold: 2
    • Port for HTTP health checks: 80
    • URL for health checks: /
CLI
Terraform
API

Run this command:

yc load-balancer network-load-balancer create test-load-balancer-2 \
   --listener name=test-listener,`
             `port=80,`
             `target-port=81,`
             `protocol=tcp,`
             `external-ip-version=ipv4 \
   --target-group target-group-id=enpu2l7q9kth********,`
                 `healthcheck-name=http,`
                 `healthcheck-interval=2s,`
                 `healthcheck-timeout=1s,`
                 `healthcheck-unhealthythreshold=2,`
                 `healthcheck-healthythreshold=2,`
                 `healthcheck-http-port=80,`
                 `healthcheck-http-path=/
  1. In the configuration file, describe the load balancer, including the listener and attached_target_group sections:

    resource "yandex_lb_network_load_balancer" "foo" {
      name = "test-load-balancer-2"
      deletion_protection = "true"
      listener {
        name        = "test-listener"
        port        = 80
        target_port = 81
        protocol    = "tcp"
        external_address_spec {
          ip_version = "ipv4"
        }
      }
      attached_target_group {
        target_group_id = "enpu2l7q9kth********"
        healthcheck {
          name                = "http"
          interval            = 2
          timeout             = 1
          unhealthy_threshold = 2
          healthy_threshold   = 2
          http_options {
            port = 80
            path = "/"
          }
        }
      }
    }
    

    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.

Use the create API method, providing the following in the request body:

{
  "folderId": "<folder_ID>",
  "name": "test-load-balancer-2",
  "type": "EXTERNAL",
  "listenerSpecs": [
    {
      "name": "test-listener",
      "port": "80",
      "protocol": "TCP",
      "targetPort": "81",
      "externalAddressSpec": {
        "ipVersion": "IPV4"
      }
    }
  ],
  "attachedTargetGroups": [
    {
      "targetGroupId": "b7rjtf12qdee********",
      "healthChecks": [
        {
          "name": "http",
          "interval": "2s",
          "timeout": "1s",
          "unhealthyThreshold": "2",
          "healthyThreshold": "2",
          "httpOptions": {
            "port": "80",
            "path": "/"
          }
        }
      ]
    }
  ]
}

Was the article helpful?

Previous
Information about existing network load balancers
Next
Creating an internal load balancer
Yandex project
© 2025 Yandex.Cloud LLC