Virtual Machine Scale Sets
The presented resiliency recommendations in this guidance include Virtual Machine Scale Sets, and dependent resources and settings.
Summary of Recommendations
Recommendations Details
VMSS-1 - 均一オーケストレーションではなく Flex オーケストレーション モードで VMSS を展開します
Category: System Efficiency
Impact: Medium
Guidance
単一インスタンスの VM でも、フレキシブル オーケストレーション モードを使用してスケール セットにデプロイし、アプリケーションのスケーリングと可用性を将来にわたって保証する必要があります。柔軟なオーケストレーションは、リージョン内または可用性ゾーン内の障害ドメインに VM を分散することで、高可用性の保証 (最大 1,000 VM) を提供します。
Resources
- When to use VMSS instead of VMs
- Azure Well-Architected Framework review - Virtual Machines and Scale Sets
Resource Graph Query
// Azure Resource Graph Query
// Find all zonal VMs that are NOT deployed with Flex orchestration mode
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| where properties.orchestrationMode != "Flexible"
| project recommendationId = "vmss-1", name, id, tags, param1 = strcat("orchestrationMode: ", tostring(properties.orchestrationMode))
VMSS-2 - VMSS アプリケーションの正常性監視を有効にします
Category: Monitoring
Impact: Medium
Guidance
アプリケーションの正常性の監視は、デプロイを管理およびアップグレードするための重要なシグナルです。Azure Virtual Machine Scale Sets は、OS イメージの自動アップグレードや VM ゲストの自動パッチ適用などのローリング アップグレードをサポートしており、個々のインスタンスの正常性の監視に依存してデプロイをアップグレードします。また、Application Health Extension を使用して、スケール セット内の各インスタンスのアプリケーション正常性を監視し、自動インスタンス修復を使用してインスタンスの修復を実行することもできます。
Resources
Resource Graph Query
// Azure Resource Graph Query
// Find all VMs that do NOT have health monitoring enabled
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| join kind=leftouter (
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| mv-expand extension=properties.virtualMachineProfile.extensionProfile.extensions
| where extension.properties.type in ( "ApplicationHealthWindows", "ApplicationHealthLinux" )
| project id
) on id
| where id1 == ""
| project recommendationId = "vmss-2", name, id, tags, param1 = "extension: null"
VMSS-3 - 自動修復ポリシーを有効にする
Category: Automation
Impact: High
Guidance
Azure Virtual Machine Scale Sets のインスタンスの自動修復を有効にすると、一連の正常なインスタンスを維持することで、アプリケーションの高可用性を実現できます。Application Health 拡張機能または Load Balancer の正常性プローブで、インスタンスが異常であることが検出される場合があります。自動インスタンス修復では、異常なインスタンスを削除し、それを置き換える新しいインスタンスを作成することで、インスタンスの修復が自動的に実行されます。
猶予期間は ISO 8601 形式で分単位で指定され、プロパティ automaticRepairsPolicy.gracePeriod を使用して設定できます。猶予期間の範囲は 10 分から 90 分で、既定値は 30 分です。
Resources
Resource Graph Query
// Azure Resource Graph Query
// Find all VMs that do NOT have automatic repair policy enabled
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| where properties.automaticRepairsPolicy.enabled == false
| project recommendationId = "vmss-3", name, id, tags, param1 = "automaticRepairsPolicy: Disabled"
VMSS-4 - VMSS Autoscale をカスタムに構成し、スケーリング メトリックを構成します
Category: System Efficiency
Impact: High
Recommendation
メトリックとスケジュールに基づくカスタム自動スケーリングを使用します。
自動スケーリングは、需要の変化に応じてアプリケーションが最適なパフォーマンスを発揮するのに役立つ組み込み機能です。リソースを特定のインスタンス数に手動でスケーリングするか、メトリックのしきい値に基づいてスケーリングするカスタム自動スケール ポリシーを使用してスケーリングするか、指定した時間枠内にスケーリングするインスタンス数をスケジュールするかを選択できます。自動スケーリングにより、需要に基づいてインスタンスを追加および削除することで、リソースのパフォーマンスとコスト効率を高めることができます。
Resources
Resource Graph Query
// Azure Resource Graph Query
// Find VMSS instances associated with autoscale settings when autoscale is disabled
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| project name, id, tags
| join kind=leftouter (
resources
| where type == "microsoft.insights/autoscalesettings"
| where tostring(properties.targetResourceUri) contains "Microsoft.Compute/virtualMachineScaleSets"
| project id = tostring(properties.targetResourceUri), autoscalesettings = properties
) on id
| where isnull(autoscalesettings) or autoscalesettings.enabled == "false"
| project recommendationId = "vmss-4", name, id, tags, param1 = "autoscalesettings: Disabled"
| order by id asc
VMSS-5 - 予測自動スケーリングを有効にし、少なくとも予測のみに構成します
Category: System Efficiency
Impact: Low
Guidance
予測自動スケーリングでは、機械学習を使用して、周期的なワークロード パターンで Azure Virtual Machine Scale Sets を管理およびスケーリングします。これにより、過去の CPU 使用率パターンに基づいて、仮想マシン スケール セットに対する全体的な CPU 負荷が予測されます。使用状況の履歴を観察して学習することで、全体的な CPU 負荷を予測します。このプロセスにより、需要を満たす時間内にスケールアウトが確実に行われます。
Resources
Resource Graph Query
// Azure Resource Graph Query
// Find VMSS instances associated with autoscale settings when predictiveAutoscalePolicy_scaleMode is disabled
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| project name, id, tags
| join kind=leftouter (
resources
| where type == "microsoft.insights/autoscalesettings"
| where tostring(properties.targetResourceUri) contains "Microsoft.Compute/virtualMachineScaleSets"
| project id = tostring(properties.targetResourceUri), autoscalesettings = properties
) on id
| where autoscalesettings.enabled == "true" and autoscalesettings.predictiveAutoscalePolicy.scaleMode == "Disabled"
| project recommendationId = "vmss-5", name, id, tags, param1 = "predictiveAutoscalePolicy_scaleMode: Disabled"
| order by id asc
VMSS-6 - スケールインおよびスケールアウトの失敗を回避するために、ゾーン間で均等に分散を強制する設定を無効にします
Category: Availability
Impact: High
Guidance
Microsoft では、VMSS 構成のリージョン内の可用性ゾーン間で VM インスタンスを厳密に均等に分散する設定を無効にすることをお勧めします。つまり、Azure が VM インスタンスをアベイラビリティーゾーン間で不均等に分散できるようにする必要があります。
ゾーン間で厳密に均等にバランスを取る: Azure には、VMSS 内の VM インスタンスをリージョン内の可用性ゾーン間で均等に分散するオプションが用意されています。可用性ゾーンは、独立した電源、冷却装置、ネットワークを備えた Azure リージョン内の物理的に分離されたデータ センターです。この構成により、アプリケーションの可用性とフォールトトレランスが向上します。
スケールインとスケールアウトの失敗の試行: VMSS のコンテキストでは、“スケールイン” とは、需要が減少したときに VM インスタンスの数を減らすことを指し、“スケールアウト” とは、需要が増加したときにインスタンスの数を増やすことを指します。スケーリングは VMSS の重要な機能であり、さまざまなスケーリング ルールとメトリックに基づいて自動的に行うことができます。
Azure VMSS には、回復性を高めるために可用性ゾーン間で VM インスタンスを均等に分散するオプションが用意されていますが、アプリケーションの負荷分散とスケーリングの要件に合わせて、このオプションを無効にすることが理にかなっているシナリオがある場合があります。
Resources
Resource Graph Query
// Azure Resource Graph Query
// Find VMSS instances where strictly zoneBalance is set to True
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| where properties.orchestrationMode == "Uniform" and properties.zoneBalance == true
| project recommendationId = "vmss-6", name, id, tags, param1 = "strictly zoneBalance: Enabled"
| order by id asc
VMSS-7 - 割り当てポリシーの拡散アルゴリズムを最大拡散に構成します
Category: System Efficiency
Impact: Medium
Guidance
最大拡散では、スケール セットによって、各ゾーン内のできるだけ多くの障害ドメインに VM が拡散されます。この拡散は、ゾーンごとに 5 つを超えるフォルト ドメインまたはより少ないフォルト ドメインにまたがる可能性があります。静的固定拡散では、スケール セットによって、ゾーンごとに正確に 5 つの障害ドメインに VM が拡散されます。スケール セットが、割り当て要求を満たすためにゾーンごとに 5 つの異なる障害ドメインを見つけられない場合、要求は失敗します。
Resources
Resource Graph Query
// Azure Resource Graph Query
// Find VMSS instances where Spreading algorithm is set to Static
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| where properties.platformFaultDomainCount > 1
| project recommendationId = "vmss-7", name, id, tags, param1 = "platformFaultDomainCount: Static"
| order by id asc
VMSS-8 - VMSS Flex を使用して可用性ゾーン間で VMSS をデプロイします
Category: Availability
Impact: High
Guidance
VMSS を作成するときは、可用性ゾーンを使用して、データセンターで発生する可能性の低い障害からアプリケーションとデータを保護します。
Resources
- Create a Virtual Machine Scale Set that uses Availability Zones
- Update scale set to add availability zones
Resource Graph Query
// Azure Resource Graph Query
// Find VMSS instances with one or no Zones selected
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| where array_length(zones) <= 1 or isnull(zones)
| project recommendationId = "vmss-8", name, id, tags, param1 = "AvailabilityZones: Single Zone"
| order by id asc
VMSS-9 - パッチ オーケストレーション オプション を Azure-orchestrated に設定します
Category: Automation
Impact: Low
Guidance
Azure VM の VM ゲストの自動修正プログラム適用を有効にすると、仮想マシンに安全かつ自動的に修正プログラムを適用してセキュリティ コンプライアンスを維持しながら、VM の影響範囲を制限することで、更新管理が容易になります。 以下の KQL では、均一オーケストレーションを使用した仮想マシン スケール セットは返されないことに注意してください。
Resources
Resource Graph Query
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| join kind=inner (
resources
| where type == "microsoft.compute/virtualmachines"
| project id = tostring(properties.virtualMachineScaleSet.id), vmproperties = properties
) on id
| extend recommendationId = "vmss-9", param1 = "patchMode: Manual", vmproperties.osProfile.linuxConfiguration.patchSettings.patchMode
| where isnotnull(vmproperties.osProfile.linuxConfiguration) and vmproperties.osProfile.linuxConfiguration.patchSettings.patchMode !in ("AutomaticByPlatform", "AutomaticByOS")
| distinct recommendationId, name, id, param1
| union (resources
| where type == "microsoft.compute/virtualmachinescalesets"
| join kind=inner (
resources
| where type == "microsoft.compute/virtualmachines"
| project id = tostring(properties.virtualMachineScaleSet.id), vmproperties = properties
) on id
| extend recommendationId = "vmss-9", param1 = "patchMode: Manual", vmproperties.osProfile.windowsConfiguration.patchSettings.patchMode
| where isnotnull(vmproperties.osProfile.windowsConfiguration) and vmproperties.osProfile.windowsConfiguration.patchSettings.patchMode !in ("AutomaticByPlatform", "AutomaticByOS")
| distinct recommendationId, name, id, param1)
VMSS-10 - 非推奨予定または既に廃止予定の VMSS イメージ バージョンをアップグレードします
Category: Governance
Impact: High
Guidance
発行元が OS イメージを引き続きサポートし、中断やセキュリティ ギャップを回避します。VM の発行元、オファー、SKU の情報を確認して、サポートされているイメージで実行されていることを確認してください。イメージの廃止に関する通知を受け取るには、ゲストの自動パッチ適用または OS イメージの自動アップグレードを有効にしてください。
Resources
Resource Graph Query
//cannot be validated with arg
VMSS-11 - 運用 VMSS インスタンスでは SSD ディスクを使用する必要があります
Category: System Efficiency
Impact: High
Guidance
運用環境のワークロードには SSD ディスクを使用することをお勧めします。HDD は重要でないリソースや、アクセス頻度の低いリソースにのみ使用する必要があるため、HDD を使用すると、リソースに影響を与える可能性があります。
Resources
Resource Graph Query
// Azure Resource Graph Query
// Find all VMSSs Uniform not using SSD storage
resources
| where type == "microsoft.compute/virtualmachinescalesets"
| where properties.orchestrationMode != "Flexible"
| where properties.virtualMachineProfile.storageProfile.osDisk.managedDisk.storageAccountType == 'Standard_LRS'
| project recommendationId = "vmss-11", name, id, tags