问题描述
我已经使用Azure VM的vhd在Azure上创建了VMSS.
I have created a VMSS on Azure using the vhd of my Azure VM.
如何将VMSS的源vhd更改为新的vhd?
How can I change the source vhd of VMSS to a new vhd ?
出现以下错误:
推荐答案
我们可以使用Update-AzureRmVmss
和Update-AzureRmVmssInstance
升级VMSS实例.
We can use Update-AzureRmVmss
and Update-AzureRmVmssInstance
to upgrade VMSS instance.
如果我们要使用自定义映像来升级Azure VMSS实例,则应确保此VMSS通过自定义映像创建.
If we want to use custom image to upgrades Azure VMSS instances, we should make sure this VMSS create by custom image.
如果我们从Azure市场创建VMSS,则无法使用自定义映像来升级Azure VMSS实例.
If we create VMSS from Azure marketplace, we can’t use custom image to upgrades Azure VMSS instances.
这是我的考试:
1.我通过自定义映像创建VMSS,并使用VMSS 模板来创建它(托管磁盘).
1.I create VMSS by custom image, and use VMSS template to create it(managed disk).
2,创建另一个VM映像,并使用以下脚本获取$ vmss,并使用Powershell升级VMSS实例:
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
这是我的屏幕截图:
我们还可以找到VMSS实例的状态:
Also we can find the status of VMSS instances:
因此,作为一种解决方法,我们可以使用模板或PowerShell使用自定义映像创建 Azure VMSS ,然后使用此脚本升级Azure VMSS实例.
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.
注意:在我的测试中,我正在使用模板创建VMSS为托管磁盘,因此我们应该使用$vmss.virtualMachineProfile.storageProfile.imageReference.id
Note: In my test, I am use template create VMSS was managed disk, so we should use $vmss.virtualMachineProfile.storageProfile.imageReference.id
如果创建的VMSS是非托管磁盘,则应使用此$vmss.virtualMachineProfile.storageProfile.osDisk.image.uri= $newURI
.
If you create VMSS was un-managed disk, we should use this $vmss.virtualMachineProfile.storageProfile.osDisk.image.uri= $newURI
.
这是有关升级VMSS实例的官方文章,请参考它.
Here is the official article about upgrades VMSS instances, please refer to it.
这篇关于更新Azure VM ScaleSet的VHD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!