INTRODUCTION
Virtual Machine Scale Set (VMSS) is a service on Azure that allows users to create and manage a group of load balanced virtual machines (VMs). The number of virtual machines can automatically increase or decrease in response to demand.
In this article, we will be discussing how to set up a virtual machine scale set in three zones (for high availability), create or add a load balancer to ensure equal distribution of traffic, scaling policy, how to stop and also delete a VMSS and its resources
Having a Microsoft Azure account or subscription is a pre-requisite for creating a VMSS. You can use the link to create a free account or log in to Azure portal to begin.
CREATE A VIRTUAL MACHINE SCALE SET
a. Type virtual machine scale set in the search bar
b. Select “Virtual machine scale sets” from the list of resources
c. Click on “Create” on the top left of the page or “Create virtual machine scale set” in the middle of the page
Basics
When you click on create, the Basics page loads and this consists of different sections like project details, instance, scaling, admin account.
Project details
a. Leave the “Azure subscription 1” as default
b. Click on “Create new" under Resource group to create a new one or click on the drop down arrow to choose an existing one.
c. Give a name to your virtual machine scale set
d. Choose your region
e. Choose your availability zone. You can choose multiple zones to ensure a high availability and minimal chance of disruption. We will choose the three available zones for UK South (our chosen region).
Orchestration Mode
Orchestration modes allow you to have greater control over how virtual machine instances are managed by the scale set. It can be uniform or flexible.
Flexible orchestration mode allows different types of instances within the same scale set while in Uniform orchestration mode virtual machine scale sets use a virtual machine profile or a template to scale up to the capacity you want, mostly using identical VM instances.
a. Choose “Uniform” orchestration mode
b. Click on the drop down arrow for security type and select “Trusted launch virtual machines”.
Orchestration mode cannot be changed once a virtual machine scale set has been created.
Scaling
This is the process of adjusting the number of resources, instances, or servers to meet workload demands. There are two types; horizontal scaling and vertical.
Horizontal scaling also known as scaling out, evenly distributes traffic among virtual machines using a load balancer. It adds more instances to the environment, sharing the processing and memory workload across multiple devices. This allows automatic scaling by adding or removing computing nodes as the workload increases or decreases.
Vertical scaling can also be called scaling up and usually involves one virtual machine i.e. adds more power or capacity to existing machines such as upgrading CPU, memory, storage or network speed.
Scaling can also be manual or automatic.
Manual scaling sets the absolute number of instances to scale up or down to. This means that it allows you to set a fixed number of instances or resources to use.
Automatic scaling or autoscaling uses Azure monitor to trigger scaling actions based on predefined rules. It is a feature that dynamically adjusts the computational resources allocated to an application or service based on demand. It can be said to be a type of horizontal scaling.
a. For this demonstration, click on “Autoscaling”.
b. Click on “Configure” under scaling configuration to edit or adjust the scaling configuration or policy.
c. On the page that opens, click on the pen icon on the right to continue editing.
d. Click on the columns to adjust the following:
Default instance count: The initial number of virtual machines deployed in a scale set usually 0 to 1000 (input 4).
Minimum instance limit: The minimum count of instance you want the condition to scale down to (leave it at default, 2).
Maximum count of instances this condition will scale up to (input 20).
Scale out or Scale in CPU threshold (greater than or less than): The CPU usage percentage threshold for triggering the scale out or scale in autoscale rule. If CPU usage is more than 80%, it automatically scales out and less than 20% of the CPU is being used, it scales in.
Increase instance count is the amount of instances to scale out by (input 2).
Decrease instance count is the amount of instances to scale in by (input 2).
Query duration- Engine will query CPU usage for the past 10 minutes (left as default but can be adjusted) before executing the scaling.
e. Click on “Save”.
There will be changes in the instance count and CPU threshold in the image below.
Predictive autoscaling is making a forecast about scaling without any scaling action. This is achieved by analysing historical data to detect patterns in traffic flow.
We will not be using predictive autoscaling, so leave as default.
Scale-in Policy
This gives options on how you configure the order in which your virtual machines are to be deleted during a scale-in process or operation.
a. Click on the drop down arrow to choose. For this demonstration, we will leave it as default.
b. Click “Save”
Instance details
a. Click the drop down arrow on the Image column to select the operating system or click on “See all images” to choose- we will use Ubuntu server which is a type of Linux OS.
b. Click on “See all sizes” or the drop down menu to select the size of your virtual machine. We will leave this in its default setting as highlighted below.
Administrator account
The authentication type in the admin account involves using a username and a password or using an SSH public key. We will be using the password authentication.
Type in your username in the box
Create your password
Confirm your password
Click on “Next: Spot>”
Leave details on “Spot” page as default and go to the next page, “Disk”.
Disk
a. Leave disk size as default or click on the drop down arrow to select disk size.
b. Click on drop down arrow for disk type to select “Premium SSD“. Leave all other data as default.
c. Click on “Next: Networking” to go to the next page.
Create and attach a new disk
You can decide to create and attach a new disk that is different from the one that comes with the OS.
a. Click on “Create and attach a new disk”
b. Click on the drop down arrow on “Key management” column
c. Choose “Platform-managed key”
d. Click on “Ok”
The new disk has been created and attached
e. Click on “Next: Networking>” to go to the next page
Networking
a. Click on the pen icon beside the Network interface information to edit
b. On the “Edit network interface”;
i. Click on “Basic” for network security group
ii. For Public inbound ports, click on “Allowed selected ports”
iii. Click the drop down on “Select inbound ports” to select HTTP (80)- for web server, HTTPS (443) and SSH (22)- for remote access, as we are using Ubuntu Linux OS/server.
c. Click on “Disable” for the Public IP address
d. Click on “OK” to save the changes or selections
e. Go back to Networking main page
Load balancing
Still on Networking page, go to “Load balancing”
a. Select “Azure load balancer”
b. Click on “Create a load balancer” to create a load balancer
c. On the Load balancer page, give a name to your load balancer and leave other information in their default state.
d. Click on “Create”.
e. On the main Networking page, click on “Next: Management>”
Management
a. On the Upgrade policy, click the drop down arrow to select upgrade mode (select Automatic).
b. Leave all other information as default
c. Click on “Next: Health>” to go to the next page.
Leave the information on Health and Advanced pages as default and skip to Tags.
Tags
a. Tag or name your resources for easy management and organisation.
b. Click on any of the “Review + create” highlighted below.
- New page shows “Validation passed”
c. Click on “Create”
Wait a little while for deployment of resources to be completed.
d. Click on “Go to resource”
FOR YOUR CREATED VIRTUAL SCALE SET
Overview
On the “Overview” page, you will notice that four initial instances and their statuses, as highlighted below because the default instance count was set as 4.
You can also see the zones where these instances are located, Public IP address, Operating system and its size.
Instances
Click on Instances on the left pane to see that the four default instances are running.
Despite the query duration being 10 minutes, the scale in CPU threshold of 20% or less was achieved from the onset, hence, the instances scaled in to 2 as you can see below. This is because the minimum instance limit and decreased instance count were set at 2.
*Click on instances again, you will notice only two instances running, as below.
*You can click on the instances individually to view details like instance ID, status and the zone each one is located in.
For example, Instance 1 (VivVMSS_1) is located in zone 2 of our selected region and it is running.
Networking
Settings
a. Click on the “Networking” drop down on the left pane
b. Click on “Network settings” to see your inbound ports, their port numbers and actions (delete) that can be taken on any of them, if the user wishes.
Load balancing
c. Click on the second option, “Load balancing” to view the load balancer you created
There is an option to add another load balancer, which we will not be using.
Availability and Scaling
a. Click on the drop down arrow for “Availability + Scale” on the left pane
b. Select “Scaling” to see the type of scaling configured for your resource/VMSS.
c. Choose “custom autoscale” if not already highlighted for you.
Because there was a scale-in due to low CPU usage, the instance count is 2.
Scaling Conditions
Scroll down the page to view the other aspects of scaling.
a. Default condition is autoscale but can be changed by clicking the pen icon beside it. The screw-top icon at the extreme right of the default condition is to disable autoscale.
b. Select “Scale based on metric” for scale mode.
c. Rules already show the earlier pre-selected scaling conditions and instance count based on CPU usage.
You can click on the “Add a rule” box to add a scaling rule if there was none or you want to add another rule.
Scale-out rule
a. Click on the green box on the highlighted column to edit the scale out conditions (if you wish to).
b. A box will pop-up on the right of the page and the arrow in blue boxes can be used to change the options and the numbers can be edited.
c. Click on “Update” when you finish editing or making changes.
Scale-in rule
a. Click on the green box on the highlighted column to edit the scale in conditions (if you wish to).
b. A box will pop-up on the right of the page and the arrow in blue boxes can be used to change the options and the numbers can be edited.
c. Click on “Update” when you finish editing or making changes.
You can click on the “Add a scale condition” box to add one.
A box pops up like the one below showing “Profile 1”, which can be modified.
Scale mode, instance count, schedule, time zone, start and end dates can be modified to your preference.
You can also click on the “Delete” icon if not needed.
STOPPING YOUR VMSS
a. Go back and click on your VMSS
b. Click on “Overview”
c. Click on “Stop” as highlighted in the image below, to stop your VMSS.
NB: Reverse the steps to start the VMSS again.
Instances
a. Click on “Instances” on the left pane to view all the instances
b. The red box shows the instances that were stopped or deallocated when the VMSS was stopped while the green box shows the ones rubbing at that moment.
Delete VMSS
a. Go back to the VMSS and click on “Overview”
b. Click on “Delete” at the top of the page, to delete the VMSS
A pop-up box appears on the screen with some prompts.
c. Tick the box “Apply force delete” to delete the VMSS and all its resources.
d. Click on “Ok” to confirm your choice.
Your VMSS will be deleted
Thanks for reading!