Create virtual machines in a scale set using an ARM template
Article
This article steps through using an ARM template to create a Virtual Machine Scale Set.
An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.
If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. The template will open in the Azure portal.
Prerequisites
If you don't have an Azure subscription, create a free account before you begin.
ARM template
An Azure Resource Manager template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax. You describe your intended deployment without writing the sequence of programming commands to create the deployment.
ARM templates let you deploy groups of related resources. In a single template, you can create the Virtual Machine Scale Set, install applications, and configure autoscale rules. With the use of variables and parameters, this template can be reused to update existing, or create additional, scale sets. You can deploy templates through the Azure portal, Azure CLI, or Azure PowerShell, or from continuous integration / continuous delivery (CI/CD) pipelines.
To create a scale with a template, you define the appropriate resources. The core parts of the Virtual Machine Scale Set resource type are:
Property
Description of property
Example template value
type
Azure resource type to create
Microsoft.Compute/virtualMachineScaleSets
name
The scale set name
myScaleSet
location
The location to create the scale set
East US
sku.name
The VM size for each scale set instance
Standard_A1
sku.capacity
The number of VM instances to initially create
2
imageReference
The platform or custom image to use for the VM instances
Canonical Ubuntu Server 16.04-LTS
osProfile.computerNamePrefix
The name prefix for each VM instance
myvmss
osProfile.adminUsername
The username for each VM instance
azureuser
osProfile.adminPassword
The password for each VM instance
P@ssw0rd!
To customize a scale set template, you can change the VM size or initial capacity. Another option is to use a different platform or a custom image.
Add a sample application
To test your scale set, install a basic web application. When you deploy a scale set, VM extensions can provide post-deployment configuration and automation tasks, such as installing an app. Scripts can be downloaded from Azure storage or GitHub, or provided to the Azure portal at extension run-time. To apply an extension to your scale set, you add the extensionProfile section to the preceding resource example. The extension profile typically defines the following properties:
Extension type
Extension publisher
Extension version
Location of configuration or install scripts
Commands to execute on the VM instances
The template uses the Custom Script Extension to install Bottle, a Python web framework, and a simple HTTP server.
Two scripts are defined in fileUris - installserver.sh, and workserver.py. These files are downloaded from GitHub, then commandToExecute runs bash installserver.sh to install and configure the app.
Deploy the template
You can also deploy a Resource Manager template by using Azure CLI:
Azure CLI
# Create a resource groupaz group create --name myResourceGroup --location EastUS
# Deploy template into resource groupaz deployment group create -g myResourceGroup -f azuredeploy.json --parameters_artifactsLocation=https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/application-workloads/python/vmss-bottle-autoscale/azuredeploy.json
Answer the prompts to provide a scale set name, instance count, and admin credentials for the VM instances. It takes a few minutes for the scale set and supporting resources to be created.
Validate the deployment
To see your scale set in action, access the sample web application in a web browser. Obtain the public IP address of the load balancer with az network public-ip list as follows:
Azure CLI
az network public-ip list \
--resource-group myResourceGroup \
--query [*].ipAddress -o tsv
Enter the public IP address of the load balancer in to a web browser in the format http://publicIpAddress:9000/do_work. The load balancer distributes traffic to one of your VM instances, as shown in the following example:
Clean up resources
When no longer needed, you can use az group delete to remove the resource group, scale set, and all related resources as follows. 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 an additional prompt to do so.
Azure CLI
az group delete --name myResourceGroup --yes--no-wait
Learn how to use Azure PowerShell to create a Virtual Machine Scale Set, along with some common management tasks such as how to start and stop an instance, or change the scale set capacity.
Learn how to use the Azure CLI to create a Virtual Machine Scale Set, along with some common management tasks such as how to start and stop an instance, or change the scale set capacity.