How to create a Load Balancer in Azure Cloud

A Load Balancer is used to evenly distribute the load on the backend servers. It acts as the single point of contact for clients requesting it. It operates at a Transport Layer of the Open Systems Interconnection (OSI) model.

Load Balancer can be either Public or Private.

  1. Public Load Balancer: External connection can reach to the Virtual Machines in the backend, it is used to balance the internet traffic to the internal VMs.
  2. Private Load Balancer: External connection can not reach to the Virtual Machines in the backend.

A load balancer can be used to scale our applications and create highly available services.

Before we create a Load Balancer, let's understand a few basic concepts related to it.

  1. Backend pool:  It is a collection of Virtual Machine IP configurations to which the load will be distributed.
  2. Health probe: It is used by the load balancer to determine if the instance is healthy or not.
  3. Load Balancer rule: It is used to define how traffic coming to the load balancer is distributed to the VMs.

With Azure Load Balancer, we only need to pay for what you use, there are no upfront charges. To know about pricing, click here.

In this article, we will create a Public Load Balancer and add a Virtual Machine to its Backend Pool. This Virtual Machine will have Apache running on it.

Pre-requisites

  1. Azure Account (Create if you don’t have one). 
  2. 1 or more Azure Virtual Machines with Apache installed on it (Search for "How to create a Virtual Machine on Azure?" to learn to create a Virtual Machine on Azure).

What will we do?

  1. Login to Azure.
  2. Create a Load Balancer

 Login to Azure

Click here to go Azure portal and click on Portal.

Use your credentials to log in to the account.

You will see the main page as follows once you successfully login to your account. Click on 3 lines near "Microsoft Azure" in the upper left-hand corner of the Azure portal to show the portal menu.

Create a Load Balancer

To create a Load Balancer, click on "All Services" from the left panel.

You will find Load Balancer under Networking, click on Load Balancer under Networking.

On the Main Dashboard for Load Balancer, click on the Add button.

Here, select the existing "Resource Group" name which contains your Virtual Machines.

Here it is "test", name the Load Balancer as test-lb, select the Region, keep the type as Public, for Public IP address select "Create new" name it as test-pub-add and click on "Next- Tags".

Add a tag as "environment: test", you can add multiple tags as per your choice. Click on "Review+ create".

Once you see the message as "Validation passed", click on "Create".

In a few mins, the Load Balancer will ready. But this is not it, we need to now add "Backend Pools". 

Click on Resource group "test" to go to the Resource Group which will contain the Load Balancer in it.

Under the resource, you can see the Load Balancer you created along with other resources. 

You should also see your virtual machine which will be behind the load balancer.

Click on the load balancer.

This is the overview page of the load balancer.

Click on "Backend Pools".

Here give a name to the Backend Pool as test-backend-pool,  select a virtual network in which your virtual machines are available.

Select "Virtual machines" for the "Associated to" option. 

Click on "Add" to add you Virtual Machines to this pool.

Select the Virtual Machines which need to be added to the Pool.

Here, we are adding only 1 VM. Save this configuration.

Now we will add "Health Probe".

Click on "Health Probe" from the left panel.

Keep this configuration as is and save it.

Now, to add Load Balancing Rules, click on "Load balancing rules" in the left panel.

Click on "Add".

Give a name to the load balancing rule as "test-lb-rule".

Since we have Apache running on Port 80 in the virtual machine added in the backend pool, no change in the rule is needed.

If you have service running on a different port, change the backend port.

Save this configuration.

Now, it's time to configure the Network Rule to allow connection on Port 80 of the Virtual Machines.

Go to the Virtual Machine, click on Networking and Add inbound security rule as follows which will allow incoming connection on Port 80 of the Virtual Machine from anywhere.

Save this rule.

To test if the Service running on Port 80 of the Virtual Machine is accessible or not, try to access the service on the IP of the Virtual Machine.

Here, we can see Apache running and accessible.

Now, it's the time to access the service through the Load Balancer we created.

Go to the Load Balancer, copy its Public IP and access it on port 80.

Here, you can see that the Service i.e. Apache is accessible from the Load Balancer which is running in the Virtual Machine in Port 80.

Conclusion

In this article, we learned to create a Public Load Balancer, added a health probe to it.

We also add a Backend Pool which contains the Virtual Machine having the service Apache running on its Port 80. We saw how the Load Balancer can be used to redirect requests to its Backend Pool.

Share this page:

0 Comment(s)