Azure Load Balancer

Azure Load Balancer

As itself, its name suggests, the Load balancer is used to split the load among several servers. Load means the number of requests coming to the server. For example, Amazon ships approximately 1.6 million packages a day. That works out to more than 66 thousand orders per hour, and 18.5 orders per second. It means there is a huge flow of requests toward amazon servers and as it is a giant e-commerce website they must be using many load balancers to balance or split the traffic equally among their servers. Also, the load balancer must do a health check of all the servers before assigning work to it, to ensure that a server is in a condition to provide service.

Load balancing refers to evenly distributing load (incoming network traffic) across a group of backend resources or servers.

Azure Load Balancer operates at layer 4 of the Open Systems Interconnection (OSI) model. The load balancer distributes inbound (incoming) flows that arrive at the load balancer's front end to backend pool instances. These flows are according to configured load-balancing rules and health probes.

Azure Load Balancer rules require a health probe to detect the endpoint status. The configuration of the health probe and probe responses determines which backend pool instances will receive new connections. Use health probes to detect the failure of an application. When a health probe fails, the load balancer will stop sending new connections to the respective unhealthy instance.

The backend pool instances can be Azure Virtual Machines or instances in a Virtual Machine Scale Set. A Virtual Machine Scale Set is a group of load-balanced VMs that can increase or decrease as per the demand or defined schedule.

Types of Load Balancers

Public Load Balancers are used to load balance internet traffic to your VMs.

An internal (or private) load balancer is used where private IPs are needed at the front end only. Internal load balancers are used to load balance traffic inside a virtual network.

Why use Azure Load Balancer?

  1. Load balances internal and external traffic to Azure virtual machines.

  2. Increase availability by distributing resources within and across zones.

  3. Configure outbound connectivity for Azure virtual machines.

  4. Use health probes to monitor load-balanced resources.

  5. Enable support for load-balancing of IPv6.

Azure Load Balancer components

Frontend IP configuration

The IP address of your Azure Load Balancer. It's the point of contact for clients. This IP Address can be either Public IP Address or Private IP Address. The nature of the IP address determines the type of load balancer created. Private IP address selection creates an internal load balancer. Public IP address selection creates a public load balancer.

Backend pool

The group of virtual machines or instances in a virtual machine scale set that is serving the incoming request. The scope of the backend pool is any virtual machine in a single virtual network.

Health probes

A health probe is used to determine the health status of the instances in the backend pool. This health probe will determine if an instance is healthy and can receive traffic.

Load Balancer rules

A load balancer rule is used to define how incoming traffic is distributed to all the instances within the backend pool. A load-balancing rule maps a given frontend IP configuration and port to multiple backend IP addresses and ports. Load Balancer rules are for inbound traffic only. For example, use a load balancer rule for port 80 to route traffic from your frontend IP to port 80 of your backend instances.

Inbound NAT rules

An inbound NAT rule forwards incoming traffic sent to the frontend IP address and port combination. The traffic is sent to a specific virtual machine or instance in the backend pool. Port forwarding is done by the same hash-based distribution as load balancing.

Image by Microsoft Learn

Outbound rules

This rule enables instances in the backend to communicate (outbound) to the internet or other endpoints.

Image by Microsoft Learn

Now let's do hands-on.

Hands-on1: public load balancer

Sign in to your Azure portal. Create a Resource Group and add all the resources that you will be creating, in this group for this hands-on. Create three VMs. To learn how to create a VM refer to this blog Azure Virtual Network

Note: While creating all VMs use default VNet in the networking tab.

Following images show how to create a VM.

Leave all the configurations in the remaining tabs as it is, click on Review+Create and deploy the VM.

Similarly, you have to create the remaining two VMs.

To learn how to create a VM in detail and access it, refer to this blog Azure Virtual Network.

  1. Download RDP files for all VMs, connect to VMs, convert these VM instances into the server and configure them. I will show you how to do that for VM1.

Open the RDP file using the credentials you set while creating the VM. This blog shows you all the steps in detail on how to connect to a VM Azure Virtual Network

Once you are connected to the VM. Go to Server Manager and follow the steps shown below.

Now repeat the same steps for VM2 and VM3. Now what you have done is you have made all these 3 VMs as Servers, and now these servers are in the backend pool of the load balancer.

  1. Create a public load balancer.

  1. Go to the next tab Frontend IP configuration and do the following.

This is the frontend IP address of our public load balancer. Traffic will come to this IP address and then the load balancer will send the request to the appropriate servers.

  1. Go to the next tab Backend Pool and do the following.

  1. Go to the next tab Inbound rules where you specify the frontendIP and backend pool, protocol and add health probe. The health probe will check the configured health probe port (HTTP port) every 15 seconds by default. The minimum probe interval is 5 seconds and can't exceed 120 seconds.

You can add outbound rules if you want. Click on Review+create, pass the validation check and create the load balancer as shown below.

Now copy the public IP of the load balancer and paste it into the browser and keep refreshing the browser and you will access all three servers that you have made.

Hands-on2: Internal Load Balancer

  1. Create a VNet, refer to Azure Virtual Network

  2. Create three VMs inside that Vnet.

  3. Convert VMs into servers.

  4. Create an internal load balancer and add VMs in the backend pool.

  5. Copy the private IP of the internal load balancer.

  1. Paste it into the browser of any server we have created and you can access the servers.

    That's all for this blog. Stay tuned for more! Happy Reading :)