Create virtual machines in a scale set using Azure CLI
This article steps through using the Azure CLI to create a Virtual Machine Scale Set.
Make sure that you've installed the latest Azure CLI and are logged in to an Azure account with az login.
Create a resource group
Create a resource group with az group create as follows:
az group create --name myResourceGroup --location chinanorth2
Create a Virtual Machine Scale Set
Important
Starting November 2023, VM scale sets created using PowerShell and Azure CLI will default to Flexible Orchestration Mode if no orchestration mode is specified. For more information about this change and what actions you should take, go to Breaking Change for VMSS PowerShell/CLI Customers - Microsoft Community Hub
Now create a Virtual Machine Scale Set with az vmss create. The following example creates a scale set with an instance count of 2, and generates SSH keys.
az vmss create \
--resource-group myResourceGroup \
--name myScaleSet \
--orchestration-mode Flexible \
--image <SKU Linux Image> \
--instance-count 2 \
--admin-username azureuser \
--generate-ssh-keys
Clean up resources
To remove your scale set and other resources, delete the resource group and all its resources with az group delete. The --no-wait
parameter returns control to the prompt without waiting for the operation to complete. The --yes
parameter confirms that you wish to delete the resources without another prompt to do so.
az group delete --name myResourceGroup --yes --no-wait