Create a network load balancer

Note

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

To create a network load balancer:

  1. Open the Load Balancer section in the folder where you want to create a load balancer.

  2. Click Create load balancer.

  3. Enter a name.

    The name must be unique within the folder. The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters.

  4. Under Listeners, assign a public IP address to the listener. You can assign an address automatically or select one from the list of reserved addresses. Click Add listener.

  5. In the window that opens, enter the listener name and specify the port number (in the range from 1 to 32767) that the load balancer will receive incoming traffic on. Click Add.

  6. Turn on Target groups.

  7. Select the VMs to be included in the new target group, or select a previously created target group.

  8. In the Health check section, enter the health check name.

    The name must be unique within the folder. The name may contain lowercase Latin letters, numbers, and hyphens. The first character must be a letter. The last character can't be a hyphen. The maximum length of the name is 63 characters.

  9. Select the check type: HTTP or TCP.

  10. Specify a port number from the range 1-32767.

  11. If you chose a check via HTTP, specify the URL to perform checks for.

  12. Specify the response timeout in seconds.

  13. Specify the interval, in seconds, for sending health check requests.

  14. Set the performance threshold, which is the number of successful checks required in order to consider the VM ready to receive traffic.

  15. Specify the failure threshold, which is the number of failed checks after which no traffic will be routed to the VM.

  16. Click Create load balancer.

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. View a description of the CLI command to create a network load balancer:

    $ yc load-balancer network-load-balancer create --help
    
  2. To create a load balancer with a listener, run the following command in the terminal:

    $ yc load-balancer network-load-balancer create \
    --region-id ru-central1 \
    --name test-load-balancer-2 \
    --listener name=test-listener,external-ip-version=ipv4,port=80
    
  3. 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 a new load balancer using the create API method.

Examples

Creating a load balancer without a listener

To create a load balancer without a listener, run the following command in the terminal:

   $ yc load-balancer network-load-balancer create \
   --region-id ru-central1 \
   --name test-load-balancer-1

Creating a load balancer with a listener and attached target group

  1. To create a load balancer with a listener and immediately connect a previously created target group to it, get the list of target groups:

    $ yc load-balancer target-group list
    +----------------------+-------------------+---------------------+-------------+--------------+
    |          ID          |       NAME        |       CREATED       |  REGION ID  | TARGET COUNT |
    +----------------------+-------------------+---------------------+-------------+--------------+
    | b7roi767je4c574iivrk | test-target-group | 2018-12-03 14:41:04 | ru-central1 |            1 |
    +----------------------+-------------------+---------------------+-------------+--------------+
    
  2. Run the following command using the target group ID in the target-group-id parameter:

    $ yc load-balancer network-load-balancer create \
    --region-id ru-central1 \
    --name test-load-balancer-3 \
    --listener name=test-listener,external-ip-version=ipv4,port=80 \
    --target-group target-group-id=b7rjtf12qdeehrj31hri,healthcheck-name=http,healthcheck-interval=2s,healthcheck-timeout=1s,healthcheck-unhealthythreshold=2,healthcheck-healthythreshold=2,healthcheck-http-port=80
    

    Mind the healthcheck-interval and healthcheck-timeout parameter format: the values must be in Ns format.