You are currently viewing Azure virtual machines scale sets with load balancer

Azure virtual machines scale sets with load balancer

In this article, we will see what are virtual machines scale sets (VMSS) and how to create it using Azure Portal and CLI.

What is VMSS ?

Please note that virtual machines and virtual machine scale sets are two different offerings from Azure.

Azure virtual machines is appropriate service for the on-premise applications which immediately want to move to cloud, enabling lift-and-shift kind of migration. But let’s say this application needs to run behind a load balancer. In order to support this scenario, you will have to:

  • create a load balancer,
  • then manually create multiple virtual machines
  • then configure monitoring,
  • Manage each resource separately etc.

In addition, you will also need to provision all the virtual machines together at once. What if your application has high load only for few hours every day and you want to configure dynamic scaling ? It is not possible.

Here comes VMSS for rescue. Virtual machine scale sets (VMSS) lets you create group of identical, load balanced virtual machines. The number of virtual machine instances can increase or decrease in response to load dynamically. OR this scaling can also be scheduled.

Why to use it ?

There can be a number of reasons why VMSS can be preferred. Below are some of the important reasons:

  • High Availability and Resiliency, multiple instances of virtual machines can be spawned instantly and hence enabling application to be available even when demand is high. Also, the virtual machine instances can be distributed among various Availability Zones to different data centers or availability zones
  • Dynamic scaling, rules can be configured to spawn the instances when demand is high and scaling down when demand is again low. The number of instances can also be configured to change based on schedule. Both these options can be helpful for saving some costs as you do not need to create all the virtual machines upfront.
  • Ability to serve large scale applications, a virtual machine scale set can scale upto 1000 virtual machines instances.

Create Load Balancer

Now, we will see how the virtual machine scale sets can be created using Azure Portal. We will first create load balancer and then we will use it while creating VMSS instance

Login to Azure Portal and search for Load Balancer in the search box provided in the top navigation and select it from the list. On the new panel, click on Add button to add a new load balancer.

On create new load balancer panel, provide below inputs:

  • Subscription, a valid Azure subscription
  • Resource Group, logical container for the resource
  • Name, any valid name, e.g. my-load-balancer
  • Region, Azure region where the resource would be located
  • Type, this can be internal or public. Select public for this demo.
  • SKU, the pricing tier. Select Standard tier.
  • Public IP Address, select create new option.
  • Public IP Address Name, any valid name, e.g. my-public-ip
  • Assignment, select static assignment

Then click on Review + Create button, which will initiate the validation. Once validation is successful, hit Create button to create the load balancer.

Azure Portal: Create public load balancer

Create VMSS

In Azure Portal, search for virtual machine scale sets in the search box provided in top navigation. On the new panel, select Add button to add new VMSS instance.

On new panel, provide below inputs in Basics tab:

  • Subscription, a valid subscription
  • Resource Group, a valid logical container. Provide the same which was created for load balancer in previous step, so that cleanup is easy.
  • Virtual machine scale set name, a valid name for VMSS
  • Region, an Azure region where this resource will be located physically
  • Availability zone, unique physical location within an Azure region. I have selected zone 1 and 2.
  • Image, the operating system for the virtual machines
  • Azure spot instance, select NO here.
  • Size, keep it default for this demo

Then select password authentication and provide username password which can be used to connect. Then click on Next button.

Azure Portal: Create virtual machine scale set

On Disks tab, keep the defaults and click on Next button.

On Networking tab, under load balancing, select YES to keep the VMSS behind the load balancer. Then perform below steps:

  • In Load balancing options, select Azure load balancer.
  • In Select a load balancer, select my-first-load-balancer that you created earlier.
  • For Select a backend pool, select Create new, type my-backend-pool, then select Create.

When you are done, select Review + create. After validation is passed, then click on create button.

That’s it, we have created a VMSS instance which uses public load balancer.

Azure CLI

Refer the documentation of az vmss create to understand how Azure CLI can be used to create VMSS instance.

Below is two step script which will create Azure VMSS. The command will also automatically create load balancer for the VMSS.

I hope you enjoyed this article. Let me know your thoughts.

Leave a ReplyCancel reply