Load balancing

One of the ways to improve scalability and the Resiliency of a cloud application is to scale out the application itself by adding more instances when needed. This guarantees better performances in general and it can help to avoid busy services.

Load balancing is a common technique that allows for an improved distribution of workloads across multiple resources by optimizing the usage of a resource, its response time and its load.

With the Azure platform, if your service uses Azure App Service or Azure Cloud Services, they are already load balanced by the platform itself. However, if your application uses Azure Virtual Machines for your workloads, you will need to provision a load balancer.

With Azure, you can use Azure Load Balancer or Azure Traffic Manager to achieve this goal.

The difference between these two platforms are essentially:

  • Azure Load Balancer routes traffic inside a region (round robin policy)
  • Azure Load Balancer works at TCP/UDP level, routing traffic between endpoints that sits behind a public endpoint
  • Azure Traffic Manager routes traffic globally based on flexible policies (not only round robin)
  • Azure Traffic Manager works at DNS level, routing traffic between endpoints that sits behind a common DNS

When using VM for your workloads and you want to improve Resiliency, it's recommended you deploy the virtual machines (VMs) (at least two) in the same subnet and using the same availability set for the two VMs (this is a requirement for Azure Load Balancer). The Load Balancer will be configured to have a public IP address and clients will send the requests to the public IP address of the Load Balancer, which in turn will redirect the requests to the appropriate VM.

The following diagram shows the solution:

Now, imagine that you have two Azure VMs on the same subnet and on the same availability set, myAvailSet (they also have the same resource group called MyRG).

To create a Load Balancer in the Azure portal, perform the following steps:

  1. Click on + and select Networking | Load Balancer:
  1. In the Create load balancer pane, give it a name of PacktLoadBalancer, select Type as Public and create a Public IP address by clicking on the appropriate section. Then select the Azure subscription to use and select MyRG as the Resource group:
  1. Click Create and the Load Balancer will be deployed.

 

  1. When the Load Balancer is deployed, select it from your resources and select Backend pools:
  1. Click Add to create a new backend pool, give it a name, select Associated to as Availability set and select the Availability set of your Azure VMs as myAvailSet:
  1. Now you can select the Azure VMs that you want to add under the Load Balancer:
  1. After adding the Azure VMs, you need to create what is called a health probe. Now click on Health probes | Add and configure your Load Balancer health probe here. Here, I've select Protocol as HTTP because my Load Balancer balances traffic on HTTP port 80:
  1. Click OK to deploy the health probe.
  2. After the health probe creation, you need to create a Load Balancer rule by selecting the Load balancing rules option:
  1. Click Add and create your load balancing rule:
  1. The last step is creating your inbound NAT rules for forwarding the traffic from the Load Balancer to the VMs (inbound NAT rules forward traffic from frontend ports to backend ports). To do this, select the Inbound NAT rules option of the Load Balancer configuration, and create a new rule for every VM in your availability set:

Your Load Balancing rule is now ready to go.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.98.208