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
Enter the subscription of Servers from its card.
Open the subsection Load Balancers from the left side menu.
{/* ๐ธ SCREENSHOT 1 ยท left menu with the Load Balancers subsection */}

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.
{/* ๐ธ SCREENSHOT 2 ยท selecting the Network and the New rule button */}

Step 3. Configure network, IP and ports
Choose the network with Select network.
Select one Public IP from those available for that network.
Define the Protocol (
TCPorUDP), the Public Port (through which requests from the Internet enter, for example80or443) and the Private Port (to which they are forwarded internally).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.
{/* ๐ธ SCREENSHOT 3 ยท Public IP, Protocol, Public Port and Private Port fields */}

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.
{/* ๐ธ SCREENSHOT 4 ยท Specify option with the allowed IP or range */}

Step 5. Choose the algorithm and affinity
Select how requests are distributed among the pool's servers:
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.
{/* ๐ธ SCREENSHOT 5 ยท selecting the algorithm and the affinity option */}

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.
{/* ๐ธ SCREENSHOT 6 ยท selecting the pool servers with the added check mark */}

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:
On Windows, from PowerShell:
And on each server in the pool, confirm that the service is listening on the private port. On Linux:
On Windows:
If something doesn't fit
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.
Last updated
Was this helpful?

