Updating VHD of Azure VM ScaleSet

让人想犯罪 __ 提交于 2020-01-04 05:26:10

问题


I have created a VMSS on Azure using the vhd of my Azure VM.

How can I change the source vhd of VMSS to a new vhd ?

Get the following error:


回答1:


We can use Update-AzureRmVmss and Update-AzureRmVmssInstance to upgrade VMSS instance.

If we want to use custom image to upgrades Azure VMSS instances, we should make sure this VMSS create by custom image.

If we create VMSS from Azure marketplace, we can’t use custom image to upgrades Azure VMSS instances.

Here is my test:

1.I create VMSS by custom image, and use VMSS template to create it(managed disk).

2, create another VM image, and use this script to get the $vmss, and use Powershell to upgrades VMSS instances:

$rgname = "vmsss"
$vmssname = "jasonvmss"
$instanceid = "1"
$newimagereference = "/subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/jasonwin/providers/Microsoft.Compute/images/myImage"
$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssname
$vmss.virtualMachineProfile.storageProfile.imageReference.id = $newImageReference
Update-AzureRmVmss -ResourceGroupName $rgname -Name $vmssname -VirtualMachineScaleSet $vmss
Update-AzureRmVmssInstance -ResourceGroupName $rgname -VMScaleSetName $vmssname -InstanceId $instanceId

Here is my screenshot:

Also we can find the status of VMSS instances:

So, as a workaround, we can use template or PowerShell to create Azure VMSS with custom image, then use this script to upgrades Azure VMSS instances.

Note: In my test, I am use template create VMSS was managed disk, so we should use $vmss.virtualMachineProfile.storageProfile.imageReference.id

If you create VMSS was un-managed disk, we should use this $vmss.virtualMachineProfile.storageProfile.osDisk.image.uri= $newURI.

Here is the official article about upgrades VMSS instances, please refer to it.




回答2:


AS per the FAQ on VMSS and VM in general, the VMSS runs on top of VHD. So, if you have a new VHD, then you could simply delete the old VMSS, and create a new VMSS.

here is how I picture your situation to be.

  1. VMSS running top of VHD1
  2. Now, I have VHD2.
  3. Create new VMSS using VHD2 as the base.
  4. Delete VMSS running on top of VHD1
  5. Delete VHD1 as well if that is no longer required, and or push it to some backup for later reuse.

the issue itself seems straightforward, unless you are asking for something else, and I am making a fool of myself :)

if the issue is something else, then the question needs to be explained a little more so other, more experience azure folks can help you.



来源:https://stackoverflow.com/questions/46000566/updating-vhd-of-azure-vm-scaleset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!