The Microsoft Azure load balancer allows developers and system administrators to distribute traffic to back-end virtual machines. Load Balancing provides a higher level of availability across virtual machines, helping to allocate resources, optimize app performance, and increase uptime. Programmers can use the Azure portal to create a basic load balancer and balance internal traffic among their virtual machines. In this Azure tutorial, we will demonstrate how to configure a load balancer through the Microsoft Azure portal.
How to Configure a Load Balancer in Azure
This load balancing tutorial assumes that the reader knows how to create a virtual machine in Azure and that you also know how to install IIS.
To demonstrate load balancer functionality, we have created two virtual machines (VMs) and named them:
- Virtual Machine 1: LBDemo1
- Virtual Machine 2: LBDemo2
After creating the above Windows virtual machines, we installed IIS.
After you have replicated these two steps, open the virtual machine LBDemo1 and copy the Public IP address to verify the IIS web status. See below:
LBDemo1 Created
To verify the IIS service is running in the LBDemo1 virtual machine, just paste the Public IP address in the web browser and hit Enter. The IIS server should be running successfully:
IIS Default Web Page
Next, open the virtual machine LBDemo2 and copy the Public IP address to verify the IIS web status:
LBDemo2 VM Created
Again, to verify the IIS service is running in the LBDemo2 virtual machine, just paste the Public IP address in the web browser and hit Enter, as we did before. The IIS server should be running successfully.
IIS Default Web Page
Next, in the Azure portal, click on the + Create a Resource, and then type Load Balancer. On the Load Balancer page, click the Create button to start creating a new load balancer.
Create Load Balancer
Now it is time to name your load balancer and assign it an IP address name. Give it the name: DemoLB and the Public IP address name of LBIP. Then, click the Review+Create button.
Add Load Balancer Public IP
After successfully creating the load balancer, open the load balancer and check the Overview section. You will find a section titled Backend Pool, Note that Load Balancer Rule and Health Probe are not filled n. See below:
Load Balancer Overview
Next, we will add the above-created virtual machines to the load balancer. To add the load balancer, click Backend Pools and then +Add.
Load Balancer Backend Pools
In the Backend Pool Name page, enter the Backend Pool Name and then select the virtual machine. Click Add to add both of the virtual machines we created in previous steps.
Backend Pools
After adding both of the virtual machines in the Backend Pool you will get the following page:
Backend Pools Created
After this, we need to configure Health Probes.Click Health Probes:
Health Probes
Then, click +Add to enter the Health Probes details:
Create Health Probes
Enter a name for Health Probes, the Protocol, Port, and other pertinent details, as depicted below:
Add Details for Health Probes
The following Health Probe should be successfully created:
Now, we need to create the Load Balancing Rules. Click Load Balancing Rules and then +Add.
In the Load Balancing Rules, map the Public IP address and Port Number of incoming traffic to the private IP address and port number of the virtual machine:
Add Load Balancer Rules
Finally, we can verify if our load balancer is configured. If so, it should be visible in our Backend Pool and Public IP address. Copy the Public IP address and enter into a web browser. The default IIS page from the LBDemo1 virtual machine should respond.
If we shut down the LBDemo virtual machine and refresh the web browser, the default IIS page from the LBDemo2 virtual machine server will respond.