[Yandex Cloud documentation](../index.md) > [Yandex Application Load Balancer](index.md) > Getting started

# Getting started with Yandex Application Load Balancer


Yandex Application Load Balancer is a cloud service terminating TLS connections and routing requests to backend applications. Application Load Balancer operates at Layer 7 of the [OSI model](https://ru.wikipedia.org/wiki/OSI_model), supporting HTTP and HTTPS protocols.

In this tutorial, you will deploy the Application Load Balancer infrastructure and configure traffic routing to the test application backend.

This infrastructure includes:

* [Target group](concepts/target-group.md)
* [Backend group](concepts/backend-group.md)
* [HTTP router](concepts/http-router.md)
* [L7 load balancer](concepts/application-load-balancer.md)

Below we explain how to create each component individually. Alternatively, you can [use the wizard](quickstart-wizard.md) to create all components at once.

## Getting started {#before-begin}

1. Log in to the [management console](https://console.yandex.cloud) or sign up. If not signed up yet, navigate to the management console and follow the on-screen instructions.
1. On the [**Yandex Cloud Billing**](https://center.yandex.cloud/billing/accounts) page, make sure you have a linked [billing account](../billing/concepts/billing-account.md) with the `ACTIVE` or `TRIAL_ACTIVE` status. If you do not have a billing account yet, [create one](../billing/quickstart/index.md#create_billing_account).
1. If you do not have a folder yet, [create one](../resource-manager/operations/folder/create.md). While creating a folder, you can also create a default virtual network with subnets in all availability zones.

## Create a VM and set up a test web server on it {#create-vm}

1. [Create](../compute/operations/vm-create/create-linux-vm.md) the `test-vm1` VM from the [Ubuntu 24.04](https://yandex.cloud/en/marketplace/products/yc/ubuntu-2404-lts-oslogin) public image in the `ru-central1-a` availability zone.
   
1. [Connect to your VM over SSH](../compute/operations/vm-connect/ssh.md).
   
    If you have the [Yandex Cloud CLI](../cli/quickstart.md) installed, you can connect to your VM via [OS Login](../compute/operations/vm-connect/os-login.md):

    ```bash
    yc compute ssh --name test-vm1
    ```
    

1. Start a test web server listening on port `8080`:

    ```bash
    mkdir test-server; echo 'HELLO' > test-server/hello.txt; python3 -m http.server -d test-server 8080
    ```

1. Make sure your web server returns a list of subdirectories in the `test-server` directory. Open the terminal on your computer and run this command:

    ```bash
    curl --verbose <VM_public_IP_address>:8080
    ```

## Create a target group {#create-target-group}

The system will deploy your application backends on the [target group](concepts/target-group.md) VM. The load balancer will distribute requests to your application backend endpoints via the target group.

In our example, the target group will consist of a single VM.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you want to create your target group.
  1. Navigate to **Application Load Balancer**.
  1. In the left-hand menu, select **Target groups**.
  1. Click **Create target group**.
  1. Specify the target group name: `test-target-group`.
  1. Select `test-vm1`.
  1. Click **Create**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../cli/quickstart.md#install).

  Run this command:

  ```bash
  yc alb target-group create test-target-group \
    --target subnet-name=<VM_subnet_name>,ip-address=<VM_internal_IP_address>
  ```

{% endlist %}

## Create a backend group {#create-backend-group}

[Backend groups](concepts/backend-group.md) contain traffic distribution rules and health check configurations for targets. Create a group and add a backend to it.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the left-hand menu, select **Backend groups**.
  1. Click **Create backend group**.
  1. Specify your backend group name: `test-backend-group`.
  1. Under **Backends**, click **Add**. Specify the backend settings:
      1. Specify the backend name: `backend-1`.
      1. From the **Target group** list, select `test-target-group`.
      1. Set the port to `8080`.
  1. Expand **Protocol settings**:
      1. Select the `HTTP` type.
  1. Click **Add health check** and configure health checks:
      1. **Timeout, s**: `1`.
      1. **Interval**: `3`.
      1. **Healthy threshold**: `2`.
      1. **Unhealthy threshold**: `2`.
      1. **Port**: `8080`.
      1. **Type**: `HTTP`.
      1. **Path**: `/`.
  1. Click **Create**.

- CLI {#cli}

  1. Create a backend group:

      ```bash
      yc alb backend-group create test-backend-group
      ```

  1. Create a backend and a health check:

      ```bash
      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=/
      ```

{% endlist %}

## Create an HTTP router {#create-http-router}

[HTTP routers](concepts/http-router.md) implement rules for client-to-backend traffic and allow you to modify requests at the load balancer layer.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the left-hand menu, select **HTTP routers**.
  1. Click **Create HTTP router**.
  1. Specify the router name: `test-http-router`.
  1. Under **Virtual hosts**, click **Add virtual host**.
  1. Specify the host name: `test-virtual-host`.
  1. Click **Add route**.
  1. Enter `test-route` as the **Name**.
  1. In the **Path** field, select `Starts with` and specify the `/` path.
  1. In the **Action** field, keep `Routing`.
  1. From the **Backend group** list, select `test-backend-group`.
  1. Do not change other settings. Click **Create**.

- CLI {#cli}

  1. Create an HTTP router:

      ```bash
      yc alb http-router create test-http-router
      ```

  1. Create a virtual host:

      ```bash
      yc alb virtual-host create test-virtual-host --http-router-name test-http-router
      ```

  1. Add a route:

      ```bash
      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
      ```

{% endlist %}

## Create an L7 load balancer {#create-load-balancer}

A [load balancer](concepts/application-load-balancer.md) distributes incoming requests across target group VMs according to the rules specified in the HTTP router. Load balancers use [listeners](concepts/application-load-balancer.md#listener) to receive traffic.

In the following example, we will deploy a load balancer and its backend node in the same subnet and availability zone.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the left-hand menu, select **Load balancers**.
  1. Click **Create L7 load balancer**.
  1. Specify the load balancer name: `test-load-balancer`.
  1. Under **Network settings**, select the network containing the subnet where you want to place your load balancer node.
  1. Under **Allocation**, select a subnet in your preferred [availability zone](../overview/concepts/geo-scope.md) and configure it to enable incoming traffic.

      Remove other availability zones by clicking ![xmark](../_assets/console-icons/xmark.svg) in each zone’s row.

  1. Under **Listeners**, click **Add listener** and specify listener settings:
      1. Specify the listener name: `test-listener`.
      1. Under **Public IP address**, enable traffic.
      1. Set the port to `80`.
      1. Select the **Automatically** type.
  1. In the **HTTP router** field, select `test-http-router`.
  1. Click **Create**.

- CLI {#cli}

  1. Create a load balancer and its backend node in the same subnet:

      ```bash
      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
      ```

  1. Add a listener:

      ```bash
      yc alb load-balancer add-listener test-load-balancer \
        --listener-name test-listener \
        --http-router-id <HTTP_router_ID> \
        --external-ipv4-endpoint port=80
      ```

{% endlist %}

## Test the load balancer {#test}

In the terminal, run this command:

```bash
curl --verbose <load_balancer_public_IP_address>:80
```

The response must return HTTP `200` with an HTML list of test VM web root subdirectories.

Next, you can expand your target group by adding more VMs, create additional application backends, and set up routes to their endpoints.

## How to delete the resources you created {#clear-out}

To stop paying for the resources you created, delete them in the following order:

{% list tabs group=instructions %}

- Management console {#console}

  1. [Delete](operations/application-load-balancer-delete.md) the `test-load-balancer` L7 load balancer.
  1. [Delete](operations/http-router-delete.md) the `test-http-router` HTTP router.
  1. [Delete](operations/backend-group-delete.md) the `test-backend-group` backend group.
  1. [Delete](operations/target-group-delete.md) the `test-target-group` target group.
   
{% endlist %}