Create a virtual machine scale set from a custom VM image with the Azure CLI
This script creates a virtual machine scale set that uses a custom VM image as the source for the VM instances.
To run this sample, install the latest version of the Azure CLI. To start, run
az login to create a connection with Azure.
Samples for the Azure CLI are written for the
bash shell. To run this sample in Windows PowerShell or Command Prompt, you may need to change
elements of the script.
#!/bin/bash # Create a resource group az group create --name myResourceGroup --location eastus # Create a scale set # Custom VM image must already exist in your subscription # See https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/tutorial-use-custom-image-cli # Network resources such as an Azure load balancer are automatically created az vmss create \ --resource-group myResourceGroup \ --name myScaleSet \ --image myImage \ --upgrade-policy-mode automatic \ --admin-username azureuser \ --generate-ssh-keys
Clean up deployment
Run the following command to remove the resource group, scale set, and all related resources.
az group delete --name myResourceGroup
This script uses the following commands to create a resource group, virtual machine scale set, and all related resources. Each command in the table links to command specific documentation.
|az group create||Creates a resource group in which all resources are stored.|
|az vmss create||Creates the virtual machine scale set and connects it to the virtual network, subnet, and network security group. A load balancer is also created to distribute traffic to multiple VM instances. This command also specifies the VM image to be used and administrative credentials.|
|az group delete||Deletes a resource group including all nested resources.|
For more information on the Azure CLI, see Azure CLI documentation.