Supercharge Your Infrastructure: Crafting Azure Virtual Machine Scale Sets from Captured VM Images in Azure Compute Gallery
Tags: cloudcomputing, azure, virtualmachine, cloud
Published: 2023-08-27 21:54:28

## Introduction

In the ever-evolving world of cloud computing, scalability is key. Whether you're a startup gearing up for rapid growth or an established enterprise managing variable workloads, Azure Virtual Machine Scale Sets (VMSS) can be a game-changer. This versatile Azure service allows you to effortlessly manage and scale multiple virtual machines (VMs) while ensuring high availability and ease of management. In this award-winning blog, we'll walk you through creating a VMSS from a compute gallery in the Azure Portal, unlocking the potential for your applications to scale dynamically.

## Why VMSS and Compute Gallery?

Before we dive into the steps, let's understand the significance of using VMSS with a compute gallery.

Azure Compute Gallery is a powerful feature that allows you to create and manage custom virtual machine images. These images can include your desired operating system, applications, and configurations. VMSS, on the other hand, is an Azure service that lets you deploy and manage a set of identical VMs. Combining these two technologies allows you to scale applications horizontally by deploying VMs based on custom images from the gallery.

Click [Here](https://dev.to/princemaxi/unlock-the-magic-mastering-azures-compute-gallery-and-vm-image-creation-10ij) to Learn How to Create a Compute Gallery and Capture a VM Image

## Benefit of Azure Virtual Machine Scale Set

Azure Virtual Machine Scale Sets (VMSS) offer several benefits for managing and deploying virtual machines in Microsoft Azure:

- **High Availability:** VMSS automatically distributes VM instances across multiple fault domains and update domains to ensure high availability. If a VM becomes unhealthy, it can be automatically replaced with a new one, reducing downtime.

- **Scalability:** VMSS allows you to easily scale your applications up or down based on demand. You can define scaling rules to add or remove VM instances automatically, ensuring your application can handle varying workloads efficiently.

- **Automatic Updates:** You can configure VMSS to perform rolling updates, ensuring that your VM instances are always up-to-date with the latest patches and software updates without causing downtime.

- **Custom Images:** VMSS supports custom VM images, allowing you to create and configure a single VM, capture its image, and then use that image to scale out instances. This simplifies deployment and ensures consistency across VM instances.

- **Managed Disks:** VMSS can use managed disks, providing features like automatic backups, replication, and enhanced reliability.

- **Auto Scaling:** You can define auto-scaling rules based on performance metrics, such as CPU utilization or memory usage, to automatically adjust the number of VM instances to match your application's needs.

- **Integrated Monitoring:** VMSS integrates with Azure Monitor, allowing you to collect and analyze performance data, set up alerts, and gain insights into the health and performance of your VM instances.

- **Cost-Efficiency:** VMSS can help optimize costs by automatically scaling down when demand is low and scaling up when demand increases, ensuring you only pay for the resources you need.

- **Ease of Management: **VMSS simplifies the management of a group of VMs. You can define a common configuration for all instances in the set and make changes centrally, reducing administrative overhead.

- **Rolling Upgrades:** When you update the underlying image or configuration of your VM instances, VMSS can perform rolling upgrades to minimize application downtime and ensure a smooth update process.

- **Template-Based Deployment:** You can use Azure Resource Manager (ARM) templates to define and deploy VMSS instances, making it easier to replicate your application environments consistently.

- **Integration with Azure DevOps:** VMSS can be integrated into your CI/CD pipeline, allowing you to automate the deployment and scaling of your applications.

- **Global Deployment:** You can use VMSS to deploy VM instances across multiple Azure regions, improving the resilience and availability of your applications.

## Prerequisites

Before you begin, ensure that you have the following prerequisites in place:

**Azure Subscription:** You need an active Azure subscription. If you don't have one, you can sign up for a free trial at Azure Portal.

**Azure Resource Group:** Create an Azure Resource Group to organize and manage your gallery resources.

**Azure Compute Gallery:** Make sure you have created a compute gallery and have captured the image of the VM you want to scale. Click [here](https://dev.to/princemaxi/unlock-the-magic-mastering-azures-compute-gallery-and-vm-image-creation-10ij) to learn how to create a compute gallery and capture a VM.

## Creating a VM Scale Set

Login to the Azure Portal home page.

![Azure Portal](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwxaglyqn97zxsp4m815.png)

Click on 'Create a resource' and search for 'Virtual Machine Scale Set'. Select it.

![Create a resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7wk1ltdm0wo50bl42vfa.png)

![Create a resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lbba1p4oe89jafu6t7b4.png)

Click on 'Create'.

![Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vc7uutakc3w9k2jodpy.png)

**Basics:** Fill out the basic information, such as the subscription, resource group, and region. Give your VMSS a unique name.

![basic information](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nleayfbzonxjlrzhd4mp.png)

**Orchestration:** _The orchestration mode is defined when you create the scale set and cannot be changed or updated later. There are two types in Azure, the Uniform and flexible orchestration. Scale sets with **Uniform orchestration** is Optimized for large-scale stateless workloads with identical instances while Scale sets with **Flexible orchestration** is used to achieve high availability at scale with identical or multiple virtual machine types._

Select the **'Flexible orchestration'**; _With Flexible orchestration, Azure provides a unified experience across the Azure VM ecosystem. Flexible orchestration offers high availability guarantees (up to 1000 VMs) by spreading VMs across fault domains in a region or within an Availability Zone. This enables you to scale out your application while maintaining fault domain isolation that is essential to run quorum-based or stateful workloads, including:_

_Quorum-based workloads
Open-source databases
Stateful applications
Services that require high availability and large scale
Services that want to mix virtual machine types or leverage Spot and on-demand VMs together
Existing Availability Set applications_

![Orchestration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/snwftmil2dllb4orhw0p.png)

**Instance Details:** Configure instance details, such as the VM image, VM architecture and instance size.

select the 'gallery image' you created earlier. This is where the power of Compute Gallery comes into play. You can choose the specific version you want to deploy.

![gallery image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmepvpsnherzoo7mtphk.png)

This will automatically select the VM architecture and VM size that was used in the VM we captured in our compute gallery.

![gallery image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nl8ch10cez87hgc8iurw.png)

**Administrator Account:** This is where you setup the username and password of your VMSS, but because we selected the Specialised operating system state when we captured the VM image it is grayed out because we no longer need authentication when we want to scale out.

Make sure you choose a 'licensing type' and check the box to confirm you have an eligible windows license. For the purpose of the VMSS we are to scale, we optioned for 'windows server' since we are scaling out to manage network traffic.

![licensing type](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99gx6xdzjmvhn4x0rqvr.png)

**Scaling:** Configure scaling options based on your application needs. 

![Scaling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tsu2y8ri9vrsz3gu0kw9.png)

Select 'Custom scaling' so that you can define scaling rules for automatic scaling. Here we define;
- initial instance count to 2.
- minimum number of instance to 1
- maximum number of instance to 10
- the VMSS to scale out in 5 minutes once the CPU threshold gets to 75% by 2 instances.
- the VMSS to scale in, in 5 minutes once the CPU threshold gets to 25% by 2 instances.

![custom scaling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m7z75thmkz0tdp36b7jq.png)

![custom scaling](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p0bxxa7p02tla0m2b63d.png)

**Management:** Specify monitoring, diagnostics, and auto-shutdown settings as per your requirements or leave it on default just like I did.

**Tags:** Ensure that your resources are tagged and you can add tags based on your preference.

![Tags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9xaujir48m5pj8mkwzfo.png)

**Review + Create:** Review your settings, and when everything looks good, click 'Create' to deploy your VM Scale Set.

![Review + Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8bwoe3i943fnqci0w7tt.png)

![Review + Create](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yj3hhho97w4rkxa2p26k.png)

This will take a while, Once deployment is completed, click on 'Go to resource' to access the newly created VMSS.

![Go to resource](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tt8xeyj9rzkr4v61ll31.png)

This is the newly deployed Virtual Machine Scale Set and you can see 2 initial instance defined during configuration are already running.

![deployed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74ibx72zth57g2qgpusu.png)

![deployed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vcfoq9mkalic8eheml85.png)

_Step 3: Monitor and Manage Your VMSS

Once your VMSS is deployed, you can use Azure Monitor and Azure Autoscale to ensure your application scales efficiently and is highly available. Azure Monitor helps you gain insights into your VMSS's performance, while Autoscale allows you to automate scaling based on metrics and schedules._

Conclusion

In this comprehensive guide, we've explored the process of creating a Virtual Machine Scale Set (VMSS) from a custom image in Azure Compute Gallery. By leveraging these Azure services, you can optimize the scalability and availability of your applications, ensuring they can handle varying workloads with ease.

VMSS and Compute Gallery are indispensable tools in your cloud infrastructure toolbox, empowering you to deploy, manage, and scale virtual machines efficiently. As you embark on your cloud journey, remember that flexibility and scalability are your allies, and Azure is your trusted partner in achieving your goals.

Embrace the power of Azure VMSS and Compute Gallery to unlock the true potential of your cloud applications. Scale up, scale out, and scale confidently with Microsoft Azure.