How to Create a Virtual Machine Scale Set in Azure

Introduction to Virtual Machine Scale Sets in Azure

Managing cloud infrastructure can be daunting, especially as your needs grow and evolve. That's where Virtual Machine Scale Sets (VMSS) in Azure come into play. VMSS provides an efficient and flexible way to deploy, manage, and scale large sets of virtual machines. Whether you're handling web applications, large-scale computations, or a high-traffic website, VMSS ensures that your infrastructure can adapt seamlessly to varying demands.

In this guide, we'll explore the essentials of creating and managing Virtual Machine Scale Sets in Azure. From setting up and configuring your scale sets to leveraging their full potential with automation and load balancing, you'll gain a comprehensive understanding of how to use VMSS to its fullest. By the end of this guide, you'll know how to maintain a robust, scalable, and cost-effective infrastructure with ease. Creating a Virtual Machine Scale Set (VMSS) in Azure allows you to manage and automatically scale a group of virtual machines.

Step-by-Step Guide: Creating Your Azure Virtual Machine Scale Set

Here's a step-by-step guide to create a VMSS using the Azure portal:

Step 1: Get Started, Accessing the Azure Portal

Open your web browser and go to the Azure portal.
Sign in with your Azure account credentials.

Step 2: Locating VMSS in Azure

Once you're in, navigate to the Virtual Machine scale set tab. If you prefer, you can quickly locate it by using the search bar at the top. This straightforward step sets the stage for creating and managing your virtual machine scale set (VMSS) effortlessly.

Click "Create" to start the creation process.

Step 3: Basic Configuration for Your VMSS

Subscription: Select your Azure subscription.
Resource Group: Select an existing resource group or create a new one.
Name: Enter a name for your scale set.
Region: Choose the region where you want to deploy the VMSS.
Availability Zone: (Optional) Select an availability zone if required.

[select or create resource group, name, region, and availability zone]

Orchestration mode: Choose Uniform (recommended for most scenarios) or Flexible.

Scaling mode: Choose Autoscaling, there are other options.
For Scaling configuration click on Configure

Step 4: Configuring Scaling for Your VMSS

Scaling conditions: Click on the edit icon to change the scaling conditions

Configure Scaling Settings
Default instance Count: Once created it creates 2 virtual machines as default.

Instance limits: Minimum is the least number of virtual machines to scale down to. I chose 1. Then Maximum is the highest number of virtual machines to scale up to. I chose 5. Ensure to save after editing.

Scaling Policy: Configure the scaling policy to automatically increase or decrease the number of instances based on CPU usage, memory, or custom metrics. Select the conditions, then click on Save

This takes us back to Scaling Configuration where the scale condition added appears. save.

Click on Save, which takes us back to where we started to Create a virtual machine scale set the next step is to configure instance details.

Step 5: Instance Details Configuration

Image: Select an operating system image for your VMs (e.g., Ubuntu Server 22.04 LTS - x64 Gen2).
Size: Choose a VM size (e.g., Standard_B1s - 1 vcpu, 1 GiB memory).
For Authentication type select SSH public key

Step 6: Ensuring Connectivity and Load Balancing

To edit the network interface, click on the edit icon.

Select allow selected ports. Select inbound ports; Select HTTP (80), SSH (22)

Also, enable Public IP address then click Ok

Select network interface and on the Load balancing options select Azure load balancer. On Select a load balancer, if there is no existing load balancer, click on Create a load balancer.

A load balancer helps to distribute traffic across the VMs (virtual machines). Add load balancer name and click create.

After creating a load balancer, click on Review and create

Step 7: Downloading Your Private Key

Once validation is passed, click on create. Click on Download private key and create resource.

When deployment is complete, click on Go to resource

Establishing a Secure SSH Connection

Go to Command prompt and run as administrator.

Open a CMD (Command prompt) window so you can run the SSH connection string. At the prompt, connect to the virtual machine using SSH. Be sure to include the correct path to the key and the virtual machine’s public_ip_address. Example of key location: C:\Users\user\Downloads\VMSS1_key.pem. When prompted, type yes to connect. “azureuser” is the username of the VMSS.

 ssh -i C:\Users\user\Downloads\VMSS1_key.pem azureuser@public_ip_address -p 50000

Ensure the command is successful and the prompt changes to azureuser@vmss1. Fetch the list of available OS updates and install updates. When prompted, type yes to continue. Each command must be completed successfully.

This “azureuser@vmss1.” would then come up again, insert the code below

sudo apt-get update

Deploy Nginx: Setting Up Your Web Service on Azure

Continue working at the CMD prompt (Command prompt). Run these commands one at a time. Ensure each command is completed successfully.

Once the previous runs successfully insert the code below

sudo apt-get -y install nginx

Let it load. Once that is done, launch the Nginx welcome page. You can open the Nginx default page in a browser, http://public_ip_address.

Clean Up: Efficiently Removing Unneeded Azure Resources

When you no longer need your virtual machine and related resources, you can easily clean them up. First, navigate to the Home page on the Azure portal. From there, select the resource group you want to delete, in this case, "RG1."

Once you're on the resource group page, simply click on Delete resource group at the top of the page. This will remove the resource group along with all its associated resources, ensuring your Azure environment stays tidy and organized (Also to incur fewer costs).

To finalize the deletion, type or copy and paste the name of the resource group. This step confirms your intention to delete the resource group and all associated resources, ensuring everything is removed safely and correctly.

Conclusion

In conclusion, creating a Virtual Machine Scale Set (VMSS) in Azure is a powerful way to manage and scale your cloud infrastructure efficiently. By following the step-by-step guide, you can set up a VMSS that automatically adjusts to your workload demands, ensuring optimal performance and cost-effectiveness. With features like autoscaling, load balancing, and easy configuration, VMSS provides a robust solution for handling varying traffic and computational needs. Whether you're running web applications or large-scale computations, Azure's VMSS offers the flexibility and reliability needed to maintain a seamless and scalable infrastructure.

0
Subscribe to my newsletter

Read articles from Uzomah Chiemerie directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Uzomah Chiemerie
Uzomah Chiemerie