Azure Virtual Machine Scale Set Instances Upgrade with Zero Downtime – Rolling Update

In this blog post I am going to cover these topics:

  • How to create an Azure Virtual Machine Scale Set which allows the upgrade of its instances with zero downtime
  • How to upgrade the VMSS instances one after another with zero downtime

Now let’s start:

Create an Azure Virtual Machine Scale Set which allows instances upgrade with zero downtime

In this section we use PowerShell to create a Virtual Machine Scale Set (VMSS) on Azure. We have to configure it in a way which would allow us to upgrade its instances one after another when needed.

That is why in the code below we have to define the UpgradePolicyMode to be Manual using the New-AzureRmVmssConfig Cmdlet.

Please take note in this example we are creating a VMSS using a base image URI (provided in the variable $imageuri).

So here is the code:

Upgrade the VMSS instances one after another with zero downtime

The code below will update the instances in the VMSS one after another. Please take note we are making two tasks in the code below:

  • We ensure any new instances will spin up from a new base image URI (provided in the variable $newImageURI)

$vmssObject = Get-AzureRmVmss -ResourceGroupName $greenrg -VMScaleSetName $vmssName
$vmssObject.virtualMachineProfile.storageProfile.osDisk.image.uri= $newImageURI
$instances = Get-AzureRmVmssVM -VMScaleSetName $vmssName -ResourceGroupName $greenrg

  • We make sure the existing instances in the VMSS will be updated with the new base image (provided in the variable $newImageURI) one after another (and not all together). This ensures we will have no downtime.

foreach($instance in $instances){
Update-AzureRmVmssInstance -ResourceGroupName $greenrg -VMScaleSetName $vmssName -InstanceId $instance.InstanceID
}

So here is the code:

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: