Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Network Load Balancer
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Network load balancers
      • Create a network load balancer
      • Create an internal network load balancer
      • Start a load balancer
      • Stop a load balancer
      • Delete a load balancer
      • Check target health statuses
      • Add a listener
      • Delete a listener
    • Target groups
      • Create a target group
      • Attach a target group to a load balancer
      • Detach a target group from a load balancer
      • Delete a target group
  • Concepts
    • Network load balancer
    • Internal network load balancer
    • Listener
    • Targets and groups
    • Resource health checks
    • Quotas and limits
  • Best practices for using the service
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • NetworkLoadBalancerService
      • TargetGroupService
      • OperationService
    • REST
      • Overview
      • NetworkLoadBalancer
        • Overview
        • addListener
        • attachTargetGroup
        • create
        • delete
        • detachTargetGroup
        • get
        • getTargetStates
        • list
        • listOperations
        • removeListener
        • start
        • stop
        • update
      • TargetGroup
        • Overview
        • addTargets
        • create
        • delete
        • get
        • list
        • listOperations
        • removeTargets
        • update
      • Operation
        • Overview
        • get
  • Questions and answers
  1. Step-by-step instructions
  2. Network load balancers
  3. Create an internal network load balancer

Create an internal network load balancer

Written by
Yandex Cloud
,
improved by
Roman M.
  • Examples
    • Creating an internal load balancer without a listener
    • Creating an internal load balancer with a listener and attached target group

The feature is at the Preview stage.

Note

The internal load balancer's listener is assigned a random IP address from the range of addresses of the selected subnet.

CLI
API
Terraform

If you don't have the Yandex Cloud command line interface, install 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.

  1. Before creating a load balancer, create a target group to attach to it.

  2. View a description of the CLI command to create a network load balancer:

    yc load-balancer network-load-balancer create --help
    
  3. To create an internal load balancer with a listener, run the following command:

    yc load-balancer network-load-balancer create \
      --name internal-lb-test \
      --type internal \
      --region-id ru-central1 \
      --listener name=test-listener,port=80,internal-subnet-id=<subnet ID>,internal-address=<internal IP address from subnet address range>
    
  4. Get the list of all load balancers to make sure that the load balancer was created:

    yc load-balancer network-load-balancer list
    

You can create an internal load balancer using the create API method.

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.

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

If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.

If you don't have Terraform, install it and configure the Yandex Cloud provider.

To create an internal network load balancer with a listener:

  1. In the configuration file, describe the parameters of resources that you want to create:

    • name: The name of the network load balancer.
    • type: The type of the network load balancer. Use internal to create an internal network load balancer.
    • listener: The listener parameters.
      • name: The name of the listener.
      • port: The port to receive traffic.
      • internal_address_spec: The specification of the internal load balancer's listener.
        • address: Internal IP address from the range of the selected subnet.
        • subnet_id: The subnet..

    Example configuration file structure:

    provider "yandex" {
        token     = "<OAuth or static key of service account>"
        folder_id = "<folder ID>"
        zone      = "ru-central1-a"
      }
    
    resource "yandex_lb_network_load_balancer" "internal-lb-test" {
      name = "internal-lb-test"
      type = "internal"
    
      listener {
        name = "my-listener"
        port = 8080
        internal_address_spec {
          address   = "<internal IP address>"
          subnet_id = "<subnet ID>"
        }
      }
    

    For more information about the resources you can create using Terraform, see the provider documentation.

  2. Make sure that the configuration files are correct.

    1. In the command line, go to the directory where you created the configuration file.
    2. Run the check using the command:
      terraform plan
      

    If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.

  3. Deploy the cloud resources.

    1. If the configuration doesn't contain any errors, run the command:
      terraform apply
      
    2. Confirm that you want to create the resources.

    Afterwards, all the necessary resources are created in the specified folder. You can check that the resources are there with the correct settings using the management console.

Examples

Creating an internal load balancer without a listener

CLI
Terraform

To create an internal load balancer without a listener, run the command:

yc load-balancer network-load-balancer create \
  --name internal-lb-test-1 \
  --type internal \
  --region-id ru-central1
  1. In the configuration file, describe the resource parameters without the listener section:

    Example of creating an internal network load balancer without a listener using Terraform
    resource "yandex_lb_network_load_balancer" "internal-lb-test" {
      name = "internal-lb-test"
      type = "internal"
    

    For more information about resources that you can create using Terraform, see the provider documentation.

  2. Make sure that the configuration files are correct.

    1. In the command line, go to the directory where you created the configuration file.

    2. Run the check using the command:

      terraform plan
      

    If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.

  3. Deploy the cloud resources.

    1. If the configuration doesn't contain any errors, run the command:

      terraform apply
      
    2. Confirm the resource creation: type yes in the terminal and press Enter.

      Afterwards, all the necessary resources are created in the specified folder. You can verify that the resources are there and properly configured in the management console or using the following CLI command:

      yc load-balancer network-load-balancer get <name of internal network load balancer>
      

Creating an internal load balancer with a listener and attached target group

CLI
Terraform
  1. To create an internal load balancer with a listener and immediately attach a target group to it, get the list of target groups:

    yc load-balancer target-group list
    

    Result:

    +----------------------+------------------+---------------------+-------------+--------------+
    |          ID          |       NAME       |       CREATED       |  REGION ID  | TARGET COUNT |
    +----------------------+------------------+---------------------+-------------+--------------+
    | b7rv80bfibkph3ekqqle | test-internal-tg | 2020-08-09 07:49:18 | ru-central1 |            3 |
    +----------------------+------------------+---------------------+-------------+--------------+
    
  2. Run the command using the target group ID in the target-group-id parameter:

    yc load-balancer network-load-balancer create \
      --name internal-lb-test-3 \
      --type internal \
      --region-id ru-central1 \
      --listener name=test-listener,port=80,internal-subnet-id=e9b81t3kjmi0auoi0vpj,internal-address=10.10.0.14 \
      --target-group target-group-id=b7rv80bfibkph3ekqqle,healthcheck-name=http,healthcheck-interval=2s,healthcheck-timeout=1s,healthcheck-unhealthythreshold=2,healthcheck-healthythreshold=2,healthcheck-http-port=80
    

    Note the format of the healthcheck-interval and healthcheck-timeout parameters: specify their values as Ns, where N is the value in seconds.

  1. To create an internal network load balancer with a listener, open the Terraform configuration file and add the listener section to the internal network load balancer's description. To attach a target group, add the attached_target_group section and specify the target group in the target_group_id field.

    Example of creating an internal network load balancer with a listener and attached target group using Terraform
    resource "yandex_lb_network_load_balancer" "internal-lb-test" {
      name = "internal-lb-test"
      type = "internal"
      listener {
        name = "my-listener"
    	     port = 9000
        internal_address_spec {
          subnet_id  = "b0cp4drld130kuprafls"
          ip_version = "ipv4"
        }
      }
      attached_target_group {
        target_group_id = "${yandex_lb_target_group.my-target-group.id}"
        healthcheck {
          name = "http"
            http_options {
              port = 9000
              path = "/ping"
            }
        }
      }
    }
    

    For more information about resources that you can create using Terraform, see the provider documentation.

  2. Make sure that the configuration files are correct.

    1. In the command line, go to the directory where you created the configuration file.

    2. Run the check using the command:

      terraform plan
      

    If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.

  3. Deploy the cloud resources.

    1. If the configuration doesn't contain any errors, run the command:

      terraform apply
      
    2. Confirm the resource creation: type yes in the terminal and press Enter.

      Afterwards, all the necessary resources are created in the specified folder. You can verify that the resources are there and properly configured in the management console or using the following CLI command:

      yc load-balancer network-load-balancer get <name of internal network load balancer>
      

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Examples
  • Creating an internal load balancer without a listener
  • Creating an internal load balancer with a listener and attached target group