Load Balancer and Virtual Machine Scale set
Tags: loadbalancer, virtualmachinescaleset, distributetraffic, vmss
Published: 2023-06-30 18:25:38

Load balancers and Virtual Machine Scale sets are different tools or services, but both are excellent infrastructure for achieving scalability and high availability of applications in Cloud environment.

Before we embark on highlighting how the two works, let's look at what each of them really are.

**Load Balancer** is a networking component or service that distributes incoming network traffic across multiple backend servers, virtual machines, or other resources. As the name implies, it balances workload across these resources. It can be implemented as software or hardware appliances or as cloud-based services provided by cloud platforms.
Its main features are 
(i)traffic distribution
(ii)resources health monitoring
(iii)session persistence
(iv) SSL termination

There are different types of Load balancers classified based on specific needs and requirements. They are
<u>(i)Local/Network Load Balancer or Transport Layer Load Balancer: </u>This operates at the network layer (Layer 4) of the OSI model distributing workload based on IP addresses and port numbers. They are often hardware appliances or software solutions specifically designed for local or on-premises network environments.
<u>(ii)Application Load Balancer (ALB) or Application Layer Load Balancer:</u>It runs at the application layer (Layer 7) of the OSI model making the load balancing decisions based on information within the application layer protocols, such as HTTP headers, URLs, or cookies. ALBs are commonly used for HTTP(S) traffic and provide advanced features like content-based routing, SSL termination, and session persistence. 
<u>(iii)Global Load Balancer:</u> distributes traffic across multiple data centers or regions, allowing load balancing on a global scale. It directs requests to the nearest or least loaded data center, reducing latency and improving performance. Generally, it is used for multi-region architectures to achieve high availability and global traffic optimization. Examples of GLB architectures are DNS hosting solutions, such as Infoblox and CloudFlare; DNS service of a major public cloud providers like AWS Route53, Azure Traffic Manager.
<u>(iv)Software Load Balancer:</u> These are implemented in software and run on standard servers or virtual machines. They provide load balancing functionality without the need for specialized hardware appliances. Software load balancers are flexible and scalable, often used in cloud environments or virtualized infrastructures.
<u>(v)Reverse Proxy Load Balancer:</u> This is located between clients and backend servers, acting as a proxy for incoming requests. It receives the client requests, performs load balancing, and forwards the requests to the appropriate backend server. They are often use in handling incoming web traffic, providing SSL termination, and offering advanced caching or content delivery capabilities.
<u>(vi)DNS Load Balancer:</u> This distributes traffic by leveraging the DNS (Domain Name System) to resolve domain names to multiple IP addresses. It can direct clients to different IP addresses based on factors like geographic location or server health. DNS load balancing is an effective approach for balancing traffic across multiple resources or locations.

**Virtual Machine Scale Set (VMSS)** is a tool or service provided by cloud computing platforms, such as Microsoft Azure, that enables the management of a group of identical virtual machines as a collective unit. 
Other important features and benefits of VMSS includes 
(i)It makes deployment and management of multiple virtual machines easy by automatically creating, scaling, and distributing them based on predefined policies.
(ii)In VMSS, scaling rules and conditions are defined to automatically add or remove virtual machine instances based on demand. Adding more VM Instances is referred to as scaling out while reducing number of VM Instances is known as scaling in
(iii) It is used to update and maintain the virtual machines within the set, and this include rolling upgrades and fault domain support.

You can have more control over the way the scale set manages virtual machine instances by using the orchestration modes. When creating VMSS, the orchestration mode is defined and this can not be modified after the deployment of the scale set. 
There are two main types of orchestration modes:

<u>(i)Scale sets with Uniform orchestration:</u> It is optimized for large-scale stateless workloads with identical instances.
It uses a virtual machine template to scale up to desired capacity. It also uses identical VM instances though it has some ability to manage or customize individual virtual machine instances. Individual Uniform VM instances are exposed via the Virtual Machine Scale Set VM API commands. When it is configured with less than 100 instances, it provides fault domain high availability. It supports a full range of scale set management and orchestration, including metrics-based autoscaling, instance protection, and automatic OS upgrades.

<u>(ii)Scale sets with Flexible orchestration:</u> This achieves high availability with identical or multiple virtual machine types. Up to 1000 VMs can be provisioned in the orchestration mode. These are spread across fault domains in a region or within an Availability Zone making scaling out easily achievable. This orchestration mode works with all sizes of virtual machines.

**How does Load balancer and Virtual Machine Scale set work together?**
A load balancer receives incoming network traffic from clients. It then distributes the traffic across the virtual machines within a Virtual machine scale set. The workload is evenly distributed preventing any single virtual machine from being overwhelmed.

When demand for your application increases, a VMSS can automatically scale out by adding more virtual machine instances to handle the increased load. The load balancer ensures that the incoming traffic is distributed across all the available instances, enabling horizontal scaling and providing additional capacity.

If for any reason a virtual machine within the scale set becomes unavailable or unhealthy, the load balancer will redirect the workload meant for that Virtual machine to the remaining healthy instances, ensuring uninterrupted service enhancing applications high availability.

Load balancers performs regular health checks of each virtual machine instance within a VMSS and route traffic only to the healthy instances. If a virtual machine becomes unhealthy, the load balancer can automatically stop sending traffic to it until it recovers.

As I mentioned at the outset, you can see how Load balancers and Virtual machine scale sets work together to achieve scalability, high availability, and efficient traffic distribution for applications deployed in a cloud environment.

Let's proceed to Azure Portal to create a Load balancer and Virtual Machine Scale Set

(1)Log in to Azure Portal and type Virtual machine scale sets into the search bar

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yn3ndct8ynvsjcvjbicp.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fky1al72ohq6foe9xal5.png)

Click on 'Create'


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kaca0vpspni6wtimkgro.png)

Complete the Project details and Scale sets details 
My Subscription is **Azure Pass Sponsorship** and my Resource group is **UniRg**.I will name the scale sets **Abbyvmss** and choose **East US** as the Region 

I will leave Orchestration at default and choose the image as Windows Server 2019 under the Instance details


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8iqqe18eomcato58vycj.png)

Complete details of the Administrator account.
My username is <u>Azureuser</u> and password is <u>Password123*</u>


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2i17do7h9kii81pzbxfv.png)

(2)To configure Load balancer, click on 'Networking'

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/861plvtrd2i1fuwonk85.png)

Under 'Networking' click on **Azure load balancer**
Next click on create Load balancer. I will name it **balancer1**
Then click 'Create'

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9n6y2iz6ipi41ac8dnzf.png)

To allow traffic from the Load balancer, we have to edit the Port configuration of the Network interface

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1n0r5iljtuk4at89qpbr.png)

Click on the Edit button on the left side of the V-net

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2oefms6owmrhvm0jt2oh.png)

Click on 'Allow selected ports' under Public Inbound Port

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4c8hbvtjhrcrgeqhljzv.png)

Select HTTP(80), RDP (3389) and Click OK

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5uo7o1xclkuala6glu93.png)

(3)Go to Scaling

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jt9rph86wpebw98u37iy.png)

I will leave the Initial Instance Count at the default of 2 and Scaling Policy at Manual

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k06pduxq0jmsh8zbdl2v.png)

(4)Click on 'Health' and enable application health monitoring

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aub7t41w1i8to8y2tf0e.png)

Click on Review and Create

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4bm2bynoox9gmb3pq1zw.png)

Click on Create and allow the deployment to complete

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwet838augtrwoo4yx6r.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f588nyod3js01yevso5a.png)

(5)Go to Resource


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cojpvf9da24fajovem1a.png)

The Virtual machine scale set Abbyvmss has been created with load balancer and two virtual machine instances

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8wdultb07a1avnsz7ino.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qkr5wxbvpdk06g36wz6l.png)

The two VM Instances are running.

Trust you find this useful.Please proceed to the comment section and let's have your feedback