Open In App

How to Configure an Azure Load Balancer?

Last Updated : 20 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to set up a Load Balancer in Azure. Load Balancer is a component that splits or divides network traffic across multiple application servers. It helps in the high availability of applications. In this article, we will configure a public load balancer that is accessible through the Internet.

Introduction to Azure Load Balancer

Azure Load Balancer is a component in Azure that helps in uniform distribution of load across services. There are mainly two types of Azure load balancers public and internal. It provides load balancing across various virtual machines, scale sets, and IP addresses.

Types of Azure Load Balancers

  • Public Load Balancer: A load balancer that is exposed to the internet is the public load balancer.
  • Internal Load Balancer: A load balancer that is only available inside the network and not available through the internet is the internal load balancer. It is mainly used for internal traffic splitting.

Health Checks In Azure

Health checks in azure helps in rerouting the traffics to available resources if any of the other resources are not available. Health checks continuously check for availability of resources depending upon specified threshold and time . If it finds an unhealthy resource it forwards the traffic to other healthy resource .

Steps to configure load Balancer in Azure

  • We will first create a virtual network with Bastion host . This network will contain our Azure virtual machine VM’s . In the search box on azure portal search for virtual networks and then click create.
  • Specify your subscription and name for virtual network in your required region . Then click next to security tab . Under security tab specify the options as below . specify name for bastion and create new public ip for the same.

virtual private network>

  • On next tab “IP addresses” select starting address as ‘10.1.0.0’ and address space as ‘\16’ and then ‘Add’. Now click on add new subnet . specify following fields . This is configuration for our Virtual machines subnet

subnet settings

  • click add and again select add new subnet and specify options as below . This is configuration for subnet used by Bastion host .

Add subnet

  • Now click on ‘review+create’ . Review the specified options and then click create.
  • Now lets configure load balancer in virtual network . Search for load balancers in search . Click on create .
  • On create page first select your subscription and then select resource group same as virtual network . Then select public load balancer and specify other options as below .

Instance details

  • Now go to next . Here click on add frontend ip configuration . Under frontend Ip configuration create new public ip address for frontend and make it zone redundant. specify other options as below.

Frontend

  • Click next on backend pools . Select add backend pool . Specify options as below and give backend pool a name. select virtual network we have created as virtual network .

Add backend pool

  • Now click next to configure inbound rules . on this page select add load balancing rule . Now specify options as below .

Load balancing rule

Protocol

  • Create a new health probe with below settings .

Health Probe

  • Click save then click on review and create . After reviewing all the settings click on create.
  • Once the deployment is successful lets create a NAT gateway for outbound access to bastion. Search for NAT gateways in search and click on create . Specify the options as below .

NAT Gateway

  • Click next for outbound IP specification . Create a new public ip address and add it . Now review all configuration and click create . For subnet select backend subnet that we have created .
  • Once the NAT is set up now we will create two virtual machines for web servers . Specify options as below for virtual machine .

Create Virtual Machine

  • Specify user name and password for user . Select None for public inbound ports.
  • Now click next to configure networking . On networking tab select our virtual network and set subnet as backend subnet . select none for public ip address . Now select ‘Advanced’ for NIC .
  • Now scroll down to configure load balancing . Check ‘Put this instance behind load balancer’ once the option is selected configure load balancer . Select ‘Azure Load balancer’ under it select our created load balancer . The backend pool will be automatically selected .
  • Now go up to configure network security group . Click on create new . Specify options as below . Create a new inbound rule with service as ‘HTTP’ and priority as 100 . Add rule to security group . Click OK.

Network Security group

  • After adding security group click on review and create . Click create .
  • Similarly follow above steps to create another virtual machine . Specify different name for vm2 . Select availability zone 2 for this vm . Make sure you select existing created network security group . After configuring click create .
  • Once both virtual machines are created . Go to overview page of VM1 and click connect select Bastion . Enter Username and Password and connect to VM .
  • On VM desktop search for powershell and run below commands one by one .
Install-WindowsFeature -name Web-Server -IncludeManagementTools
Remove-Item C:\inetpub\wwwroot\iisstart.htm
Add-Content -Path "C:\inetpub\wwwroot\iisstart.htm" -Value $("Hello World from " + $env:computername)
  • If first command fails manually go to windows features options and Turn on “Internet Information Services” and “Internet Information Services Ho-stable web Core” features. After that run next two commands . Close the bastion tab .
  • Do the same for VM2 .
  • Now we have completed configuration of load balancer . Lets check the working .
  • Search for public ip address in search bar . Now go to load balancer ip address . Copy and paste it in the browser you should see similar output as below . Every time you refresh the page it will be served from different virtual machines .

Output 2

OutPut 2

  • If you see above output congratulations you have successfully configured Azure load balancer .

Troubleshooting

  • If you dont see correct output then make sure you have configured the load balancer with correct IP addresses.
  • Make sure your VM instances are in same region and resource group as load balancer .
  • Make sure IP configuration for load balancer is correct .

Best practices for configuring Azure Load Balancer

There are various options for configuring Azure Load Balancer. You can also choose other services as Traffic Manager , Application Gateway, Azure Front Door .etc . For Load Balancer best way to configure is to use group of servers as backend.

FAQs On Load Balancer

1. What Is Need Of Load Balancing In Azure ?

“Load balancers in Azure are primarily used to ensure high availability of applications and distribute the load across multiple replicas of the application, thereby reducing latency for end users.”

2. What Is Latency Improvement After Configuring Azure Load Balancer ?

After configuring Azure Load Balancer, incoming traffic to the application is distributed across multiple replicas. This distribution of traffic across replicas reduces the load on any particular replica, resulting in decreased latency for the application.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads