[Yandex Cloud documentation](../../../index.md) > [Yandex Network Load Balancer](../../index.md) > [Tutorials](../index.md) > [Fault-tolerant website with load balancing via a Network Load Balancer](index.md) > Management console

# Fault-tolerant website with load balancing via Yandex Network Load Balancer using the management console


To create a [fault-tolerant website with load balancing via Yandex Network Load Balancer](index.md) using the Yandex Cloud management console:

1. [Get your cloud ready](#before-you-begin).
1. [Create an instance group](#create-vms).
1. [Upload the website files](#upload-files).
1. [Create a network load balancer](#create-load-balancer).
1. [Test the fault tolerance](#test).

If you no longer need the resources you created, [delete them](#clear-out).


## Get your cloud ready {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../../billing/quickstart/index.md) and [link](../../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../../resource-manager/concepts/resources-hierarchy.md).


### Required paid resources {#paid-resources}

The website support cost includes:

* Fee for [disks](../../../compute/concepts/disk.md) and continuously running [VMs](../../../compute/concepts/vm.md) (see [Yandex Compute Cloud pricing](../../../compute/pricing.md)).
* Fee for using dynamic or static [public IP addresses](../../../vpc/concepts/address.md#public-addresses) (see [Yandex Virtual Private Cloud pricing](../../../vpc/pricing.md)).
* Fee for a [network load balancer](../../concepts/index.md) and traffic balancing (see [Network Load Balancer pricing](../../pricing.md)).


### Set up your environment {#configure-env}

* [Create](../../../vpc/operations/network-create.md) a cloud network named `nlb-network` and [subnets](../../../vpc/operations/subnet-create.md).
* [Create](../../../iam/operations/sa/create.md) a service account named `nlb-sa` and [assign](../../../iam/operations/sa/assign-role-for-sa.md) the `editor` role to it.
* [Create](../../../compute/operations/vm-connect/ssh.md#creating-ssh-keys) an SSH key pair.


## Create an instance group {#create-vms}

{% list tabs group=instructions %}

- Management console {#console}

  1. Open the [management console](https://console.yandex.cloud).
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups** and click **Create group of virtual machines**.
  1. Under **Basic parameters**:

      * Enter a name for the instance group, e.g., `nlb-vm-group`.
      * Select the `nlb-sa` [service account](../../../iam/concepts/users/service-accounts.md).

  1. Under **Allocation**, select the `ru-central1-a` and `ru-central1-b` availability zones to ensure fault tolerance of your hosting.
  1. Under **Instance template**, click **Define** to configure a basic instance:

      1. Under **Boot disk image**, open the **Marketplace** tab and click **Show all Marketplace products**. Choose a product:

          * [LEMP](https://yandex.cloud/en/marketplace/products/yc/lemp) for Linux, Nginx, MySQL®, and PHP
          * [LAMP](https://yandex.cloud/en/marketplace/products/yc/lamp) for Linux, Apache, MySQL®, and PHP

          Click **Use**.

      1. Under **Disks and file storages**, specify:

          * **Type**: `HDD`.
          * **Size**: `3 GB`.

      1. Under **Computing resources**, open the **Custom** tab and specify the following: 

          * **Platform**: `Intel Ice Lake`.
          * **vCPU**: `2`.
          * **Guaranteed vCPU performance**: `20%`.
          * **RAM**: `1 GB`.

      1. Under **Network settings**:

          * Select the cloud network named `nlb-network` and its subnets.
          * In the **Public address** field, select `Auto`.

      1. Under **Access**, specify the VM access credentials:

          * In the **Service account** field, select the service account to link to the VM.
          * Specify the username in the **Login** field.
          * In the **SSH key** field, paste the contents of the public key file.

      1. Click **Save**.

  1. Under **Scaling**, specify the instance group size: `2`.
  1. Under **Integration with Network Load Balancer**, select **Create target group** and enter `nlb-tg` as the group name.
  1. Click **Create**.

  It may take a few minutes to create an instance group. As soon as all VMs change their [status](../../../compute/concepts/vm-statuses.md) to `RUNNING`, you can [upload the website files to them](#upload-files).

{% endlist %}


## Upload the website files {#upload-files}

To test the web server, upload the website files to each VM. You can use the `index.html` file from [this archive](https://storage.yandexcloud.net/doc-files/index.html.zip) as an example.

For each VM in the created group, do the following:

1. [Get](../../../compute/operations/vm-info/get-info.md) the VM public IP address.
1. [Connect](../../../compute/operations/vm-connect/ssh.md) to the VM via SSH.
1. Grant your user write permissions for the `/var/www/html` directory:

    ```bash
    sudo chown -R "$USER":www-data /var/www/html
    ```

1. Upload the website files to the VM via [SCP](https://en.wikipedia.org/wiki/Secure_copy_protocol).

    {% list tabs group=operating_system %}

    - Linux/macOS {#linux-macos}

      Use the `scp` command line utility:

      ```bash
      scp -r <path_to_directory_with_files> <VM_user_name>@<VM_IP_address>:/var/www/html
      ```

    - Windows {#windows}

      Use [WinSCP](https://winscp.net/eng/download.php) to copy the local file directory to `/var/www/html` on the VM.

    {% endlist %}


## Create a network load balancer {#create-load-balancer}

When creating a network load balancer, you need to add a [listener](../../concepts/listener.md) to handle incoming traffic, attach the [target group](../../concepts/target-resources.md) created along with the instance group, and configure health checks for its targets.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder where you need to create a load balancer.
  1. Navigate to **Network Load Balancer** and click **Create a network load balancer**.
  1. Enter a name for the load balancer, e.g., `nlb-1`.
  1. Under **Listeners**:
  
      1. Click **Add listener** and specify the following settings:

          * **Name**: `nlb-listener`
          * **Port**: `80`
          * **Target port**: `80`

      1. Click **Add**.

  1. Under **Target groups**:

      1. Click **Add target group** and select the `nlb-tg` target group you [created earlier](#create-vms). If there is only one target group, it will be selected automatically.
      1. Under **Health check**, click **Configure** and specify the following:

          * **Name**: `health-check-1`.
          * **Healthy threshold**: `5`. This stands for the number of successful checks required to consider the VM ready to receive traffic.
          * **Unhealthy threshold**: `5`. This stands for the number of failed checks before traffic is no longer routed to the VM.

      1. Click **Apply**.

  1. Click **Create**.

{% endlist %}

After you create a network load balancer, [test the fault tolerance](#test).

## Test the fault tolerance {#test}

1. [Get](../../../compute/operations/vm-info/get-info.md) the public IP address of any VM from the group you created.
1. [Connect](../../../compute/operations/vm-connect/ssh.md) to the VM via SSH.
1. Stop the web service to simulate a failure on the web server:

    {% list tabs %}

    - LAMP

      ```bash
      sudo service apache2 stop
      ```

    - LEMP

      ```bash
      sudo service nginx stop
      ```

    {% endlist %}

1. [Get](../../../compute/operations/vm-info/get-info.md) the listener IP address.
1. Open the website in the browser using the listener address.

    The connection should be successful, even though one of the web servers has failed.

1. When the check is complete, start the web service again:

    {% list tabs %}

    - LAMP

        ```bash
        sudo service apache2 start
        ```

    - LEMP

        ```bash
        sudo service nginx start
        ```

    {% endlist %}


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

To shut down the hosting and stop paying for the resources you created:
1. [Delete](../../operations/load-balancer-delete.md) the network load balancer.
1. [Delete](../../../compute/operations/instance-groups/delete.md) the instance group.
1. [Delete](../../../vpc/operations/address-delete.md) the static public IP address if you reserved one.

#### See also {#see-also}

* [Fault-tolerant website with load balancing via Yandex Network Load Balancer using Terraform](terraform.md)