In this blog we will see the VMSS update by using an image with Rolling upgrade policy.
Create a VM image in the portal to update the VMSS with that image.
VMSS needs to be created with the custom image.
Creation of VM image to be used while creating a VMSS. Select capture to create a VM image.
Provide the details and create the image of VM as shown below.
After creating the VM image, wait for some time to load the image. So that your captured image will be available, search for images in portal
Create a VMSS, search for VMSS in search box. Create a VMSS
In the basics section add the required fields and use the captured image to create VMSS for that, AT IMAGE blade select browse all public and private images.
It will pop up for selecting the images and click on my items blade and the select the image
Add the authentication type as password
Click on next and leave the disks as default and click on networking, enable load balancer
In scaling section, select the scaling policy as custom and add values based on requirement or leave it default.
In the management section opt for rolling upgrade policy.
In the health section enable the monitor and from application health monitor drop down select the load balancer probe and set the protocol to TCP and port number as 22
Skip the next sections and create the VMSS
Once your VMSS is created, now we will update the VMSS using a new image, for that we will create new VM and will create sample files or directories inside the new VM and capture the image.
Once VM is created, go the serial console of it and add directory and create sample file with some text.
So I used following commands to create some files in my VM using serial console.
Now capture this vm to create a new image and get the image.reference.id
Click on newly created image to get imge.reference.id nothing but resource.id copy it paste it on notepad
Create a sample project of any name and create a release a pipeline by choosing an empty job.
And select stage 1 job and add tasks to that stage.
Then configure the agent job with agent pool and agent specification by giving name to that job.
The add a task called azure cli and configure it for VMSS update by using an image.
Select the right subscription to establish service connection to azure resources, where you have deployed the Azure VMSS. Select the script type as shell using dropdown and choose inline script and add the Az cli script.
Az cli for updating the VMSS is as follows.
az vmss show --name (VMSSNAME) --resource-group (RGName) | grep images;
##here imageReference.id needs to be given to update the vmss. Use the copied resource.id from the newly created image and use it in the below command.
az vmss update --resource-group RGname --name VMSSname --set virtualMachineProfile.storageProfile.imageReference.id=/subscriptions/xxxxxxxxxxxxxxxf788a44c3b2d/resourceGroups/xxxxx/providers/Microsoft.Compute/images/anothervm-image
az vmss show --name VMSSname --resource-group RGname | grep images;
Now create release, after completing the release, go for serial console of VMSS and check for the created sample file and directory.
Since we opted for Rolling upgrade policy each instance will update in a manner of condition’s we set that is one instance followed by another.