> 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 several servers so that 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 reaches a public IP and port, and the balancer distributes it among the pool servers according to an algorithm. For this to work, all servers in the pool have to 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 infallible.&#x20;
>
> 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 start

* 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 add them afterward.

### Step 1. Go to Load Balancers

1. Enter the **Servers** subscription
2. Open the subsection **Load Balancers** from the left sidebar menu.

{/\* 📸 CAPTURE 1 · sidebar menu with the Load Balancers subsection \*/}

![Access to the Load Balancers subsection](https://REEMPLAZA-URL/servidores-howto-lb-01.png)

### Step 2. Create a new rule

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

{/\* 📸 CAPTURE 2 · network selection and the New rule button \*/}

![Creation of a new load-balancing rule on a network](https://REEMPLAZA-URL/servidores-howto-lb-02.png)

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

1. Choose the network with **Select network**.
2. Select one **Public IP** of the available ones for that network.
3. Define the **Protocol** (`TCP` or `UDP`), the **Public Port** (through which requests enter from the Internet, for example `80` or `443`record) 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.

{/\* 📸 CAPTURE 3 · fields Public IP, Protocol, Public Port and Private Port \*/}

![Public IP, protocol, and port configuration](https://REEMPLAZA-URL/servidores-howto-lb-03.png)

### 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 specify.

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

{/\* 📸 CAPTURE 4 · Specify option with the allowed IP or range \*/}

![Definition of the networks with access to the published service](https://REEMPLAZA-URL/servidores-howto-lb-04.png)

### Step 5. Choose the algorithm and affinity

Select how requests are distributed among the pool servers:

| Algorithm         | What it does                                                        | When it fits                                           |
| ----------------- | ------------------------------------------------------------------- | ------------------------------------------------------ |
| Round Robin       | Distributes in turns, in a circular way                             | 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 to enable **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 state shared between servers, blindly distributing can cut off a user's session halfway through browsing. Affinity avoids this by tying it to one server, at the cost of slightly less even distribution.

{/\* 📸 CAPTURE 5 · selection of the algorithm and the affinity option \*/}

![Selection of the distribution algorithm and affinity](https://REEMPLAZA-URL/servidores-howto-lb-05.png)

### 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 added correctly shows a checkmark and an outline marked in Plenit color. When you're done, click **Create Rule**.

{/\* 📸 CAPTURE 6 · selection of the pool servers with the added checkmark \*/}

![Selection of the servers that make up the balancer pool](https://REEMPLAZA-URL/servidores-howto-lb-06.png)

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

During creation you'll see a message such as `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 match

| Symptom                                             | Likely cause                                           | What to do                                          |
| --------------------------------------------------- | ------------------------------------------------------ | --------------------------------------------------- |
| It won't let me create the rule because of the port | That port is already in use on the network             | Use another public port or free up 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             | Stateless distribution                                 | 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 really performs when the pool is homogeneous and you choose the algorithm that matches your workload: that's when you stop distributing requests blindly and start distributing them with criteria.


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
