Historically, the setting to use a Capacity Reservations Groups must be defined while the virtual machine is being deployed or changed while the machine is deallocated. While this is still the requirement, the drafted Azure Policy (at the bottom of this document) automates the additional setting to be specified even if it wasn’t specified on the VM Creation process.
For example, some solutions, such as Citrix DaaS hosted on Azure, use automation such as recreation of VMs to handle update management or scalability demands. The update process doesn’t have the ability to add this setting without code changes to their process which requires a significant investment of time per cloud provider to update. If this capacity isn’t available for any reason, the scale out or recreation could fail causing the environment to become unhealthy.
Azure Capacity Reservations are a new feature that allows you to reserve compute resources for your virtual machines (VMs) in a specific region and/or availability zone. By using Azure Capacity Reservations, you can ensure that your VMs have guaranteed access to the resources they need, even during periods of high demand or unexpected events.
Reserved Virtual Machine Instance (RI) to on-demand Capacity Reservation work together. You can apply existing or future RIs to on-demand capacity reservations and receive RI discounts. Available RIs are applied automatically to Capacity Reservation the same way they're applied to VMs.
Azure Capacity Reservation Group (CRG) is a grouping of Capacity Reservations. VM creation targets the CRG and not the specific Capacity Reservation.
To get started with Azure Capacity Reservations, you need to follow these steps:
To deploy your virtual machines to the capacity that is created, you need to follow either of these options:
With the below parameters set via policy per subscription, VMs of the desired SKU and availability will automatically be added based on:
Using this functionality, it is now possible to specify a minimum quantity of VM Compute that is guaranteed to be available.
Create the Capacity Reservation Group to hold the specific Capacity Reservations based on regional or zonal alignment. For each SKU, create a capacity reservation with the minimum amount of compute you wish to be reserved per region or zone. Capacity Reservations can be overallocated. If you reserve 3 nodes of E2s_v4 in zone 1, but attempt to deploy 10 VMs, you are guaranteed to have the 3 available for your consumption and the remaining 7 are subject to normal availability within the zone.
In this example, I have created a Capacity Reservation Groups for regional and another for zonal alignment:
Regional: CRGRG1-WUS3-r
Zonal: CRGRG1-WUS3-z
To simplify the experience, I have created a single Azure Policy that is able to be referenced for both scenarios.
An example copy of the policy can be found at the bottom of this article.
Based on the assignment parameters below:
This example for regional:
allowedLocations |
westus3 |
CapacityReservationID |
/subscriptions/########-####-####-####-############/resourceGroups/CRGRG/providers/Microsoft.Compute/capacityReservationGroups/CRGRG1-WUS3-r |
listOfCRGSKUs |
Standard_E2s_v4 |
Zonal |
False |
Based on the assignment parameters below (this example for zonal):
allowedLocations |
westus3 |
CapacityReservationID |
/subscriptions/########-####-####-####-############/resourceGroups/CRGRG/providers/Microsoft.Compute/capacityReservationGroups/CRGRG1-WUS3-z |
listOfCRGSKUs |
Standard_E2s_v4 |
Zonal |
True |
The above Azure Policy and assignments added this line of code in the VM Creation template.
"type": "Microsoft.Compute/virtualMachines",
"location": "westus3",
"properties": {
"capacityReservation": {
"capacityReservationGroup": {
"id": "/subscriptions/########-####-####-####-############/resourceGroups/CRGRG/providers/Microsoft.Compute/capacityReservationGroups/CRGRG1-WUS3-z"
}
}
The below policy is a draft and is based on new functionality. It should not be treated as production ready unless deemed so by the appropriate resources at your organization.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines"
},
{
"field": "location",
"in": "[parameters('allowedLocations')]"
},
{
"field": "Microsoft.Compute/virtualMachines/sku.name",
"in": "[parameters('listOfCRGSKUs')]"
},
{
"field": "Microsoft.Compute/virtualMachines/zones",
"exists": "[parameters('Zonal')]"
},
{
"field": "Microsoft.Compute/virtualMachines/capacityReservation.capacityReservationGroup.id",
"notequals": "[parameters('CapacityReservationID')]"
}
]
},
"then": {
"effect": "modify",
"details": {
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c"
],
"operations": [
{
"operation": "addOrReplace",
"field": "Microsoft.Compute/virtualMachines/capacityReservation.capacityReservationGroup.id",
"value": "[parameters('CapacityReservationID')]"
}
]
}
}
},
"parameters": {
"allowedLocations": {
"type": "Array",
"metadata": {
"displayName": "Specific Region that is covered under this CRG",
"description": "The list of locations that resource groups can be created in.",
"strongType": "location"
}
},
"listOfCRGSKUs": {
"type": "Array",
"metadata": {
"displayName": "Allowed Size SKUs",
"description": "The list of size SKUs that can be specified for virtual machines.",
"strongType": "VMSKUs"
}
},
"CapacityReservationID": {
"type": "String",
"metadata": {
"displayName": "Capacity Reservation ID",
"description": "The capacity reservation targets this policy to target. Resource ID should be formatted as: '/subscriptions/{SubID}/resourceGroups/{RGName}/providers/Microsoft.Compute/capacityReservationGroups/{CRG Name}.'"
}
},
"Zonal": {
"type": "String",
"metadata": {
"displayName": "Is this Zonal?",
"description": "If this is Zonal, it will attempt to add to the Zonal Capacity Reservation Groups. If not, it will add to the reginoal Capacity Reservation Groups."
},
"allowedValues": [
"true",
"false"
]
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.