Exercise - Update applications in Virtual Machine Scale Sets
In the shipping-company scenario, you installed a web application by creating the Virtual Machine Scale Set. You now need to update the web app and install a new version across all virtual machines (VMs) in the scale set.
You must ensure that the system remains available during the rollout. A good way to ensure availability is to use a custom script extension to do the update. Apply this script across the Virtual Machine Scale Set. The scale set applies the update to one VM at a time, leaving the other VMs up and running.
In this exercise, you use a custom script extension to roll out a new version of the web app. Edit the message that the nginx server provides. You can use the same approach for bigger updates.
Note
This exercise is optional. If you don't have an Azure account, you can read through the instructions to understand how to use the REST API to retrieve metrics.
If you want to complete this exercise, but you don't have an Azure subscription or prefer not to use your own account, create a free account before you begin.
Deploy the update by using a custom script extension
In the Azure portal, open the Cloud Shell and run the following command to view the current upgrade policy for the scale set:
az vmss show \ --name webServerScaleSet \ --resource-group myResourceGroup \ --query upgradePolicy.mode
Verify that the upgrade policy is set to
Automatic
. You specified this policy when you created the scale set in the first lab. If the policy wasManual
, you would apply any VM changes by hand. Because the policy isAutomatic
, you can use the custom script extension and allow the scale set to do the update.Run the following command to apply the update script:
az vmss extension set \ --publisher Microsoft.Azure.Extensions \ --version 2.0 \ --name CustomScript \ --vmss-name webServerScaleSet \ --resource-group myResourceGroup \ --settings "{\"commandToExecute\": \"echo This is the updated app installed on the Virtual Machine Scale Set ! > /var/www/html/index.html\"}"
Test the updated web application
Run the following command to retrieve the IP address of the load balancer for the scale set:
az network public-ip show \ --name webServerScaleSetLBPublicIP \ --resource-group myResourceGroup \ --output tsv \ --query ipAddress
In your web browser, go to the public address of the scale set load balancer. Verify that you see the message This is the updated app installed on the Virtual Machine Scale Set !.