This is part-2 of previous article and we are configuring a public load balancer in Azure which for distributing/load balancing traffic between VMs where we host an application or service.
Please read Part-1 before going through steps in this article.
In Part-1 lab, we have added two VMs (Windows Server 2016), specified Virtual Network, configured Availability sets and their public IPs. We also did setup and deploy a web application on IIS in both VMs and tested accessing those using individual URLs.
In Azure portal, add a load balancer as shown below:
Choose the type of load balancer as “Public”
Next step is to select new Load Balancer that is created and go to “Front end IP configuration” and add a public IP address. Note that once completed, we will be using this IP address for accessing the web application (MyWebApp that we created in Part-1 lab) instead of individual IPs for VMs.
Select “Backend Pools” next and click “Add”. Select your availability set where both of our VMs are associated.
Now you will be able to associate both VMs to the backend pool of load balancer as shown below.
Once done, go to Health Probes, and add a health probe for this load balancer with default settings.
The next important step is to set Load balancing rules. Add one as shown below.
Go to LoadBalancer Front End and you can find the public IP address has been associated and configuration is looking good
Now it is time to test accessing your web application. Note that we access the web application using LoadBalancer public IP.
http://<load balancer IP address>/MyWebApp
The demo below shows the results when I accessed it using two browser instances. Loadbalancer directed one to VM1 and the other to VM2
Assume that one of your Virtual Machine is down or under maintenance, the load balancer auromatically redirects the traffic to other available VMs. In our case, I have stopped VM1 (WebServerVM1) to simulate such a scenario.
Once VM is stopped, refresh the browser instance which was loaded from that VM1. Note that the load balancer redirects the request to VM2 as shown below.
Details of internal load balancing scenarios will be discussed in another article.