针对 Azure 虚拟机规模集实例的实例保护Instance Protection for Azure virtual machine scale set instances

Azure 虚拟机规模集可以通过自动缩放提高工作负荷的弹性,让你可以配置何时对基础结构进行横向扩展,何时对其进行横向缩减。Azure virtual machine scale sets enable better elasticity for your workloads through Autoscale, so you can configure when your infrastructure scales-out and when it scales-in. 规模集还可以让你通过不同的升级策略设置集中管理、配置和更新大量 VM。Scale sets also enable you to centrally manage, configure, and update a large number of VMs through different upgrade policy settings. 可以针对规模集模型配置更新,此时如果已将升级策略设置为“自动”或“滚动”,则新配置会自动应用到每个规模集实例。You can configure an update on the scale set model and the new configuration is applied automatically to every scale set instance if you've set the upgrade policy to Automatic or Rolling.

当应用程序处理流量时,有时可能需要对特定规模集实例进行不同于其他实例的处理。As your application processes traffic, there can be situations where you want specific instances to be treated differently from the rest of the scale set instance. 例如,规模集中的某些实例可能正在执行长时间运行的操作,需要在这些操作完成后再横向缩减这些实例。For example, certain instances in the scale set could be performing long-running operations, and you don't want these instances to be scaled-in until the operations complete. 另外,可能还需要让规模集中的一些实例专门执行其他任务或不同于规模集的其他成员的任务。You might also have specialized a few instances in the scale set to perform additional or different tasks than the other members of the scale set. 这些“特殊的”VM 不能与规模集中的其他实例一起修改。You require these 'special' VMs not to be modified with the other instances in the scale set. 实例保护提供的其他控制可以为应用程序实现这些方案和其他方案。Instance protection provides the additional controls to enable these and other scenarios for your application.

本文介绍如何对规模集实例应用和使用不同的实例保护功能。This article describes how you can apply and use the different instance protection capabilities with scale set instances.

实例保护类型Types of instance protection

规模集提供两类实例保护功能:Scale sets provide two types of instance protection capabilities:

  • 防止进行横向缩减Protect from scale-in

    • 通过规模集实例上的 protectFromScaleIn 属性实现Enabled through protectFromScaleIn property on the scale set instance
    • 防止对实例进行通过自动缩放启动的横向缩减Protects instance from Autoscale initiated scale-in
    • 不阻止用户启动的实例操作(包括实例删除)User-initiated instance operations (including instance delete) are not blocked
    • 不阻止在规模集上启动的操作(升级、重置映像、解除分配等)Operations initiated on the scale set (upgrade, reimage, deallocate, etc.) are not blocked
  • 防止进行规模集操作Protect from scale set actions

    • 通过规模集实例上的 protectFromScaleSetActions 属性实现Enabled through protectFromScaleSetActions property on the scale set instance
    • 防止对实例进行通过自动缩放启动的横向缩减Protects instance from Autoscale initiated scale-in
    • 防止对实例执行在规模集上启动的操作(例如升级、重置映像、解除分配等)Protects instance from operations initiated on the scale set (such as upgrade, reimage, deallocate, etc.)
    • 不阻止用户启动的实例操作(包括实例删除)User-initiated instance operations (including instance delete) are not blocked
    • 不阻止删除整个规模集Delete of the full scale set is not blocked

防止进行横向缩减Protect from scale-in

可以在规模集实例创建以后将实例保护应用到这些实例。Instance protection can be applied to scale set instances after the instances are created. 只能在实例模型上应用和修改保护,不能在规模集模型上进行。Protection is applied and modified only on the instance model and not on the scale set model.

可以通过多种方式将横向缩减保护应用到规模集实例,详见以下示例。There are multiple ways of applying scale-in protection on your scale set instances as detailed in the examples below.

Azure 门户Azure portal

可以通过 Azure 门户对规模集中的实例应用横向缩减保护。You can apply scale-in protection through the Azure portal to an instance in the scale set. 不能一次调整多个实例。You cannot adjust more than one instance at a time. 对要保护的每个实例重复以下步骤。Repeat the steps for each instance you want to protect.

  1. 转到现有虚拟机规模集。Go to an existing virtual machine scale set.
  2. 从左侧菜单的“设置” 下选择“实例” 。Select Instances from the menu on the left, under Settings.
  3. 选择要保护的实例的名称。Select the name of the instance you want to protect.
  4. 选择“保护策略” 选项卡。Select the Protection Policy tab.
  5. 在“保护策略” 边栏选项卡中,选择“防止进行横向缩减” 选项。In the Protection Policy blade, select the Protect from scale-in option.
  6. 选择“保存” 。Select Save.

REST APIREST API

以下示例将横向缩减保护应用到规模集中的实例。The following example applies scale-in protection to an instance in the scale set.

PUT on `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/virtualMachines/{instance-id}?api-version=2019-03-01`
{
  "properties": {
    "protectionPolicy": {
      "protectFromScaleIn": true
    }
  }        
}

备注

只有 API 2019-03-01 及更高版本支持实例保护Instance protection is only supported with API version 2019-03-01 and above

Azure PowerShellAzure PowerShell

使用 Update-AzVmssVM cmdlet 将横向缩减保护应用到规模集实例。Use the Update-AzVmssVM cmdlet to apply scale-in protection to your scale set instance.

以下示例将横向缩减保护应用到规模集中实例 ID 为 0 的实例。The following example applies scale-in protection to an instance in the scale set having instance ID 0.

Update-AzVmssVM `
  -ResourceGroupName "myResourceGroup" `
  -VMScaleSetName "myVMScaleSet" `
  -InstanceId 0 `
  -ProtectFromScaleIn $true

Azure CLI 2.0Azure CLI 2.0

使用 az vmss update 将横向缩减保护应用到规模集实例。Use az vmss update to apply scale-in protection to your scale set instance.

以下示例将横向缩减保护应用到规模集中实例 ID 为 0 的实例。The following example applies scale-in protection to an instance in the scale set having instance ID 0.

az vmss update \  
  --resource-group <myResourceGroup> \
  --name <myVMScaleSet> \
  --instance-id 0 \
  --protect-from-scale-in true

防止进行规模集操作Protect from scale set actions

可以在规模集实例创建以后将实例保护应用到这些实例。Instance protection can be applied to scale set instances after the instances are created. 只能在实例模型上应用和修改保护,不能在规模集模型上进行。Protection is applied and modified only on the instance model and not on the scale set model.

防止对实例进行规模集操作时,也会防止对实例进行通过自动缩放启动的横向缩减。Protecting an instance from scale set actions also protects the instance from Autoscale initiated scale-in.

可以通过多种方式将规模集操作保护应用到规模集实例,详见以下示例。There are multiple ways of applying scale set actions protection on your scale set instances as detailed in the examples below.

Azure 门户Azure portal

可以通过 Azure 门户将“使其不受规模集操作的影响”应用到规模集中的一个实例。You can apply protection from scale set actions through the Azure portal to an instance in the scale set. 不能一次调整多个实例。You cannot adjust more than one instance at a time. 对要保护的每个实例重复以下步骤。Repeat the steps for each instance you want to protect.

  1. 转到现有虚拟机规模集。Go to an existing virtual machine scale set.
  2. 从左侧菜单的“设置” 下选择“实例” 。Select Instances from the menu on the left, under Settings.
  3. 选择要保护的实例的名称。Select the name of the instance you want to protect.
  4. 选择“保护策略” 选项卡。Select the Protection Policy tab.
  5. 在“保护策略” 边栏选项卡中,选择“使其不受规模集操作的影响” 选项。In the Protection Policy blade, select the Protect from scale set actions option.
  6. 选择“保存” 。Select Save.

REST APIREST API

以下示例将规模集操作保护应用到规模集中的实例。The following example applies protection from scale set actions to an instance in the scale set.

PUT on `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vMScaleSetName}/virtualMachines/{instance-id}?api-version=2019-03-01`
{
  "properties": {
    "protectionPolicy": {
      "protectFromScaleIn": true,
      "protectFromScaleSetActions": true
    }
  }        
}

备注

只有 API 2019-03-01 及更高版本支持实例保护。Instance protection is only supported with API version 2019-03-01 and above.
防止对实例进行规模集操作时,也会防止对实例进行通过自动缩放启动的横向缩减。Protecting an instance from scale set actions also protects the instance from Autoscale initiated scale-in. 设置 "protectFromScaleSetActions": true 时,不能指定 "protectFromScaleIn": falseYou can't specify "protectFromScaleIn": false when setting "protectFromScaleSetActions": true

Azure PowerShellAzure PowerShell

使用 Update-AzVmssVM cmdlet 将规模集操作保护应用到规模集实例。Use the Update-AzVmssVM cmdlet to apply protection from scale set actions to your scale set instance.

以下示例将规模集操作保护应用到规模集中实例 ID 为 0 的实例。The following example applies protection from scale set actions to an instance in the scale set having instance ID 0.

Update-AzVmssVM `
  -ResourceGroupName "myResourceGroup" `
  -VMScaleSetName "myVMScaleSet" `
  -InstanceId 0 `
  -ProtectFromScaleIn $true `
  -ProtectFromScaleSetAction $true

Azure CLI 2.0Azure CLI 2.0

使用 az vmss update 将规模集操作保护应用到规模集实例。Use az vmss update to apply protection from scale set actions to your scale set instance.

以下示例将规模集操作保护应用到规模集中实例 ID 为 0 的实例。The following example applies protection from scale set actions to an instance in the scale set having instance ID 0.

az vmss update \  
  --resource-group <myResourceGroup> \
  --name <myVMScaleSet> \
  --instance-id 0 \
  --protect-from-scale-in true \
  --protect-from-scale-set-actions true

故障排除Troubleshoot

不能在规模集模型上设置 protectionPolicyNo protectionPolicy on scale set model

只能在规模集实例上应用实例保护,不能在规模集模型上应用。Instance protection is only applicable on scale set instances and not on the scale set model.

不能在规模集实例模型上设置 protectionPolicyNo protectionPolicy on scale set instance model

默认情况下,保护策略不会在实例创建时应用到实例。By default, protection policy is not applied to an instance when it is created.

可以在规模集实例创建以后将实例保护应用到这些实例。You can apply instance protection to scale set instances after the instances are created.

不能应用实例保护Not able to apply instance protection

只有 API 2019-03-01 及更高版本支持实例保护。Instance protection is only supported with API version 2019-03-01 and above. 请检查所使用的 API 版本和更新是否符合要求。Check the API version being used and update as required. 可能还需要将 PowerShell 或 CLI 更新到最新版本。You might also need to update your PowerShell or CLI to the latest version.

后续步骤Next steps

了解如何在虚拟机规模集上部署应用程序Learn how to deploy your application on virtual machine scale sets.