> For the complete documentation index, see [llms.txt](https://docs.plenit.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.plenit.com/docs-en/productos/servers/how-to/how-to-deploy-a-load-balancer.md).

# How to Deploy a Load Balancer

A load balancer distributes requests among multiple servers, so none gets overloaded and the service stays up even if one fails.

In this tutorial you create a load-balancing rule over a pool of at least two servers in the same subscription.

> #### 👍 What you get
>
> A load-balancing rule that publishes a service on a public IP and distributes traffic among the servers you choose.

### How load balancing fits in

Traffic arrives at a public IP and port, and the balancer distributes it among the pool's servers according to an algorithm. For this to work, all the servers in the pool must serve the same thing: load balancing distributes the load, it does not synchronize content.

> #### 📘 It distributes load, it is not full high availability
>
> Load balancing improves availability and absorbs spikes, but it does not make your service foolproof.
>
> If one server in the pool serves something different from the others, the client will see inconsistent responses. Keep the same content and configuration on all of them.

### Before you begin

* Log in to the Plenit platform with a user who has administration permissions over the organization.
* At least **two servers** deployed in the same subscription. You can create the rule before adding them and incorporate them later.

### Step 1. Go to Load Balancers

1. Enter the subscription of **Servers** from its card.
2. Open the subsection **Load Balancers** within the servers menu.

<figure><img src="https://3894148717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxksPMyYRDCe4qKkhbpcY%2Fuploads%2Fgit-blob-b7f21f4a8a9076dfb8340e761f32903177e22b47%2FCAPTURA%201%20y%202%C2%B7%20men%C3%BA%20lateral%20con%20la%20subsecci%C3%B3n%20Load%20Balancers%20y%20network%20con%20new%20rule%20(6).jpg?alt=media" alt=""><figcaption><p>Load Balancers subsection</p></figcaption></figure>

### Step 2. Create a new rule

If there are no rules yet, you will see the start screen to create one; if they already exist, you will see the list. Select the **Network** on which you are going to create the rule and click **New rule**.

<figure><img src="https://3894148717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxksPMyYRDCe4qKkhbpcY%2Fuploads%2Fgit-blob-76c5f4a730c361ffb60e380dc636f51eb52ba3f1%2FCAPTURA%201%20y%202%C2%B7%20men%C3%BA%20lateral%20con%20la%20subsecci%C3%B3n%20Load%20Balancers%20y%20network%20con%20new%20rule%20(7).jpg?alt=media" alt="Creación de una nueva regla de balanceo sobre una red"><figcaption><p>Creation of a new load-balancing rule on a network</p></figcaption></figure>

### Step 3. Configure network, IP and ports

1. Choose the network with **Select network**.
2. Select one **Public IP** from those available for that network.
3. Define the **Protocol** (`TCP` or `UDP`), the **Public Port** (through which requests from the Internet enter, for example `80` or `443`) and the **Private Port** (to which they are forwarded internally).
4. Click **Next**.

> #### 🚧 One port, one single use per network
>
> Within the same network, a port can only be used once: there cannot be two rules for the same port in the same network space.

<figure><img src="https://3894148717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxksPMyYRDCe4qKkhbpcY%2Fuploads%2Fgit-blob-52396939d55000954e23d7ccfce62da027dfa4b0%2FCAPTURA%203%20%C2%B7%20campos%20Public%20IP%2C%20Protocol%2C%20Public%20Port%20y%20Private%20Port.jpg?alt=media" alt="Configuración de IP, protocolo y puertos"><figcaption><p>IP, protocol, and port configuration</p></figcaption></figure>

### Step 4. Define which networks will have access

Indicate from which IPs the published service can be accessed:

* **Any**: access from any network. It is the least secure option.
* **Specify**: access only from the IPs or ranges you indicate.

With **Specify**, enter the allowed IP or range (you can add several) and click **Next**.

<figure><img src="https://3894148717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxksPMyYRDCe4qKkhbpcY%2Fuploads%2Fgit-blob-f7d9c69c24d9684b74cd17ae5bbab8051929e51e%2FCAPTURA%204%20%C2%B7%20opci%C3%B3n%20Specify%20con%20la%20IP%20o%20rango%20permitido.jpg?alt=media" alt="Definición de las redes con acceso al servicio publicado"><figcaption><p>Definition of the networks with access to the published service</p></figcaption></figure>

### Step 5. Choose the algorithm and affinity

Select how requests are distributed among the pool's servers:

| Algorithm         | What it does                                                        | When it fits                                           |
| ----------------- | ------------------------------------------------------------------- | ------------------------------------------------------ |
| Round Robin       | Distributes in turns, in a circular manner                          | General case, equivalent servers                       |
| Least connections | Sends each request to the server with the fewest active connections | Requests of unequal duration                           |
| Source            | Assigns according to the source IP                                  | When the same client must always go to the same server |

Then, decide whether you enable the **affinity rules**. Enable them if the application stores session state on the server itself and does not share it between machines; if you do, complete **Table size (KB)** and **Expiration(s)**. Click **Next**.

> 📘 Affinity keeps the client on the same server
>
> Without shared state between servers, blind distribution can cut off a user's session midway through browsing. Affinity prevents this by tying it to a server, at the cost of a slightly less even distribution.

<figure><img src="https://3894148717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxksPMyYRDCe4qKkhbpcY%2Fuploads%2Fgit-blob-5f2c0f48d24b30f26284a4e56b18da43bda046a3%2FCAPTURA%205%20%C2%B7%20selecci%C3%B3n%20del%20algoritmo%20y%20la%20opci%C3%B3n%20de%20afinidad.jpg?alt=media" alt="Selección del algoritmo de reparto y la afinidad"><figcaption><p>Selection of the distribution algorithm and affinity</p></figcaption></figure>

### Step 6. Select the pool servers

Choose the machines that will respond to requests. Click each element that appears as **Not selected** and assign it the corresponding IP. A server that has been added correctly shows a check mark and the outline highlighted in Plenit's color. When you are done, click **Create Rule**.

<figure><img src="https://3894148717-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxksPMyYRDCe4qKkhbpcY%2Fuploads%2Fgit-blob-4afd16fc265381462e0f003992caeda4fc6dd625%2FCAPTURA%206%20%C2%B7%20selecci%C3%B3n%20de%20los%20servidores%20del%20pool%20con%20el%20check%20de%20a%C3%B1adido.jpg?alt=media" alt="Selección de los servidores que forman el pool del balanceador"><figcaption><p>Selection of the servers that make up the load balancer pool</p></figcaption></figure>

### Step 7. Verify that the rule has been created

During creation you will see a message like `Servers: Creating Load Balancer ...` and, when it finishes, another confirming that it was created successfully. The rule appears in the list, although you may need to refresh the screen.

To check that the service really responds, test the public endpoint from outside. On Linux or macOS:

```bash
curl -I http://<PUBLIC-IP>:<PUBLIC-PORT>
```

On Windows, from PowerShell:

```powershell
Test-NetConnection <PUBLIC-IP> -Port <PUBLIC-PORT>
```

And on each server in the pool, confirm that the service is listening on the private port. On Linux:

```bash
ss -tlnp | grep <PRIVATE-PORT>
```

On Windows:

```powershell
netstat -ano | findstr <PRIVATE-PORT>
```

### If something doesn't fit

| Symptom                                    | Likely cause                                           | What to do                                         |
| ------------------------------------------ | ------------------------------------------------------ | -------------------------------------------------- |
| Cannot create the rule because of the port | That port is already in use in the network             | Use another public port or free the existing one   |
| The public endpoint does not respond       | No server in the pool is listening on the private port | Check with `ss` / `netstat` that the service is up |
| A user loses the session while browsing    | Distribution without shared state                      | Enable affinity or share state between servers     |

### Conclusion

With this, you have a service published behind a balancer that distributes traffic among several servers, which smooths out spikes and keeps the service running even if one machine fails. Load balancing truly performs when the pool is homogeneous and you choose the algorithm that fits your workload: that's when you stop distributing requests blindly and start distributing them with purpose.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.plenit.com/docs-en/productos/servers/how-to/how-to-deploy-a-load-balancer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
