Creating a Virtual Machine Scale Set on Azure Portal
Tags: cloudcomputing, virtualmachine, azure
Published: 2024-06-27 22:48:39

A Virtual Machine Scale Set lets us easily create and manage multiple virtual machines. 
All VMs in a scale set are identical, meaning they are created from the same base operating system image and configuration. Obviously, this approach lets us easily manage hundreds of VMs without additional configuration.

For traffic distribution, an Azure Load Balancer is also deployed along with the virtual machines in a scale set.With the auto-scale feature, the number of virtual machines can automatically increase or decrease in response to demand. 

**Log in to Azure**
- Sign in to the [Azure portal](https://azure.microsoft.com/en-us/get-started/azure-portal).
- Search for Virtual Machine Scale Set
- Click on "Virtual machine scale sets" and then "Create"

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

**Create a virtual machine scale set**

In the Basics tab, under Project details, make sure the correct subscription is selected and select _NetworkwatcherRG_ from my resource group list.

- Type_VMSS_as the name for your scale set.
- In Region, select a region that is close to your area.
- Under Orchestration, ensure the Uniform option is selected for Orchestration mode.
- Select _Autoscaling_ for scaling mode
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/af21hxjy13syax84abow.png)

**Scaling Configuration**
- Select an _image_
- Select _size_
- Click on _configure_ to setup scaling configuration
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6uqs1gzgznk76qztfwvq.png)

**Add Scaling Conditions**

- Click add scaling condition

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

- Condition name -_VMSS-COND_
- Scale Mode - _Autoscaling_
- Initial instance count - 2
- Instance limit
  Minimum- 2 ,Maximum- 4
- Scale out
  CPU threshold greater than - 75%
- Increase instance count by - 1
- CPU threshold less than - 25%
- Decrease count by - 1
- Query duration - 5 minutes
- Click save

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

- Select condition
- Save

**Authentication**
- Select SSH key
- Username - _azureuser_
- SSH Keytype - _RSA SSH format_
- Azure automatically generates a key pair name
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wrntsngqj8egpx3t7df.png)

**Networking**

- Select virtual network: Azure automatically generated one, you can also select an existing virtual network.
- Edit Network Interface
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qxxxe3xeoaqptfnzwimc.png)

**Edit Network Interface**
- Leave all as default
- Public inbound ports - allow all
- Select _HTTP 80,SSH 22_
- Enable public IP address
- OK

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

**Create a Load Balancer**
- Load balancing options: Select Azure load balancer
- Click on create load balancer
- Load balancer name -_VMSS-LB_
- leave everything as default
- Click create
- Review + Create
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/loae4easjevltv3xii8w.png)

**Create Virtual Machine Scale Set**
- Validation passed
- Click create

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

**Download Private key and create resource**
- Download private key pair to your computer
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nnel7pi7yd8p3k3vja23.png)

**Deployment**
- Once deployment is complete
- Go to _resources_

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

**Virtual Machine Scale Set**
- Overview of the VMSS
- Copy the Public IP address to connect.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u68ica8l1stxth2154q3.png)

**Instances**
- We can see 2 instances running at the same time.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ghchlwlajmg9c4lbef2a.png) 

**Inbound NAT Rules**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8ivqrtgzikktq7g7tp3.png)

**Connecting to the VMSS using Command Prompt**

- Navigate to Command Prompt on a PC.
- Run this command the command below `ssh -i "path to the private key on the pc" username@publicIP -p 50000`

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

After connecting to the VM,we run some sudo commands to test
`sudo apt-get -y update`

`sudo apt-get -y install nginx`

**Testing Public IP on a Browser**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/od0grdyc8gl7jpcdgq7c.png)

**Clean up resources**
When no longer needed, delete the resource group, scale set, and all related resources. To do so, select the resource group for the scale set and then select **Delete**.