Getting started with Yandex Application Load Balancer
Yandex Application Load Balancer enables distributing requests across backends of your network applications and terminating TLS encryption. Application Load Balancer runs on Layer 7 of the OSI model
This guide will help you deploy the Application Load Balancer infrastructure and set up traffic to the test application backend.
The Yandex Application Load Balancer infrastructure includes:
Below is a description of how to create each component individually. You can also use the wizard to create all components on the same page.
Getting started
- Log in or sign up to the management console
. If not signed up yet, navigate to the management console and follow the instructions. - On the Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account yet, create one. - If you do not have a folder yet, create one. While creating a folder, you can also create a default virtual network with subnets in all availability zones.
Create a VM and launch a test web server on it
-
Create a virtual machine named
test-vm1
from the Ubuntu 24.04 public image in theru-central1-a
availability zone. -
If you have the Yandex Cloud command line interface installed, you can connect to the VM via OS Login:
yc compute ssh --name test-vm1
-
Start a test web server that will respond to requests at port
8080
:mkdir test-server; echo 'HELLO' > test-server/hello.txt; python3 -m http.server -d test-server 8080
-
Make sure the web server returns a list of folders in the
test-server
folder. Open the terminal on your computer and run this command:curl --verbose <VM_public_IP_address>:8080
Create a target group
Your application backends will be deployed on the VM instance of the target group. The target group will be connected to the load balancer so that requests might be sent to the backend endpoints of your application.
In this example, we will assume there is only one VM in the target group.
- In the management console
, select the folder to create your target group in. - In the list of services, select Application Load Balancer.
- In the left-hand menu, select Target groups.
- Click Create target group.
- Enter the target group name:
test-target-group
. - Select the VM named
test-vm1
. - Click Create.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
Run this command:
yc alb target-group create test-target-group \
--target subnet-name=<VM_subnet_name>,ip-address=<VM_internal_IP_address>
Create a backend group
Backend groups contain settings for traffic balancing and target resource health check. Create a group and add one backend to it.
- In the left-hand menu, select Backend groups.
- Click Create backend group.
- Enter the backend group name:
test-backend-group
. - Under Backends, click Add. Specify the backend settings:
- Enter the backend name:
backend-1
. - In the Target group list, select
test-target-group
. - Specify Port:
8080
.
- Enter the backend name:
- Expand the Protocol settings field and set the parameters:
- Select the
HTTP
type.
- Select the
- Click Add health check and set up the check:
- Timeout, s:
1
. - Interval:
3
. - Healthy threshold:
2
. - Unhealthy threshold:
2
. - Type:
HTTP
. - Path:
/
.
- Timeout, s:
- Click Create.
-
Create a backend group:
yc alb backend-group create test-backend-group
-
Create a backend and health check:
yc alb backend-group add-http-backend \ --backend-group-name test-backend-group \ --name backend-1 \ --port 8080 \ --target-group-name test-target-group \ --target-group-id <target_group_ID> \ --http-healthcheck healthy-threshold=2,unhealthy-threshold=2,timeout=1s,interval=3s,path=/
Create an HTTP router
HTTP routers define the rules for routing requests sent to backends and allow you to modify requests directly in the balancer.
- In the left-hand menu, select HTTP routers.
- Click Create HTTP router.
- Enter the router name:
test-http-router
. - Under Virtual hosts, click Add virtual host.
- Enter the host name:
test-virtual-host
. - Click Add route.
- Set Name to
test-route
. - In the Path field, select
Starts with
and specify the/
path. - In the Action field, keep
Routing
. - In the Backend group list, select
test-backend-group
. - Leave all other settings unchanged and click Create.
-
Create an HTTP router:
yc alb http-router create test-http-router
-
Create a virtual host:
yc alb virtual-host create test-virtual-host --http-router-name test-http-router
-
Add a route:
yc alb virtual-host append-http-route test-route \ --http-router-name test-http-router \ --prefix-path-match / \ --backend-group-name test-backend-group \ --virtual-host-name test-virtual-host
Create an L7 load balancer
A load balancer receives requests and distributes them across target group VMs according to the rules specified in the HTTP router. Load balancers use listeners to receive traffic.
As an example, let's create a balancer with a node in the same subnet and same availability zone.
-
In the left-hand menu, select Load balancers.
-
Click Create L7 load balancer.
-
Enter the load balancer name:
test-load-balancer
. -
Under Network settings, select the network whose subnet will host the load balancer node.
-
Under Allocation, select a subnet in one availability zone and enable incoming traffic in this subnet.
Remove the other availability zones by clicking
in the relevant row. -
Under Listeners, click Add listener. Set the listener settings:
- Enter the listener name:
test-listener
. - Under Public IP address, enable traffic.
- Set the port to
80
. - Select the Automatically type.
- Enter the listener name:
-
In the HTTP router field, select
test-http-router
. -
Click Create.
-
Create a load balancer with a node in the same subnet:
yc alb load-balancer create test-load-balancer \ --network-name <network_name> \ --location subnet-name=<subnet_name_in_ru-central1-a_zone>,zone=ru-central1-a
-
Add a listener:
yc alb load-balancer add-listener test-load-balancer \ --listener-name test-listener \ --http-router-id <HTTP_router_ID> \ --external-ipv4-endpoint port=80
Test the load balancer
In the terminal, run the following command:
curl --verbose <load_balancer_public_IP_address>:80
The response must return the HTTP status code 200
and an HTML list of folders from the test VM folder.
After that, you can add other VMs to the target group, create new backends for your application, and build routes to the application endpoints.
How to delete the resources you created
To stop paying for the resources you created, delete them in the following order: