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:
-
Open the Load Balancer section in the folder where you want to create a load balancer.
-
Click Create load balancer.
-
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.
-
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.
-
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.
-
Turn on Target groups.
-
Select the VMs to be included in the new target group, or select a previously created target group.
-
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.
-
Select the check type: HTTP or TCP.
-
Specify a port number from the range 1-32767.
-
If you chose a check via HTTP, specify the URL to perform checks for.
-
Specify the response timeout in seconds.
-
Specify the interval, in seconds, for sending health check requests.
-
Set the performance threshold, which is the number of successful checks required in order to consider the VM ready to receive traffic.
-
Specify the failure threshold, which is the number of failed checks after which no traffic will be routed to the VM.
-
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.
-
View a description of the CLI command to create a network load balancer:
$ yc load-balancer network-load-balancer create --help
-
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
-
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
-
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 | +----------------------+-------------------+---------------------+-------------+--------------+
-
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
andhealthcheck-timeout
parameter format: the values must be inNs
format.