Loading...

Azure Capacity Reservations with Automatic Consumption

Azure Capacity Reservations with Automatic Consumption

Solving the ask – Automatic Capacity Reservations

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.

 

What are Azure Capacity Reservations?

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.

 

How to create Azure Capacity Reservations?

To get started with Azure Capacity Reservations, you need to follow these steps:

  • Create a capacity reservation group: A reservation group is a logical container that holds one or more reservations. You can assign VMs to a reservation group to use the reserved resources.
  • Create a capacity reservation: A reservation is a specific amount of compute resources that you reserve for a certain VM size, region, and availability zone. You can create multiple reservations within a reservation group.

 

How do I use the Capacity Reservations?

To deploy your virtual machines to the capacity that is created, you need to follow either of these options:

  • Assign VMs to a reservation group: You can assign existing deallocated VMs or new VMs to a reservation group, either individually or as part of a scale set. The VMs will use the reserved resources from the reservation group, as long as they match the reservation criteria.
  • Leverage Azure Policy (New as of July 2024):
    • Using Azure policy, you can deploy a policy per subscription that specifying:
      • VM SKU
      • Region
      • Target Capacity Reservation
      • Is this a zonal deployment
    • When VMs are created, this policy will automatically add the virtual machine to the Azure Capacity Reservation Group.

 

How do I use Azure Policy to set the Capacity Reservation?

With the below parameters set via policy per subscription, VMs of the desired SKU and availability will automatically be added based on:

  • Region
  • SKU
    • Multiple SKUs can be targeted with the policy
  • Zonal – yes or no
  • Capacity Reservation ID
    • The Capacity reservation targeted with the policy will need to match the zonal decision or VM Creations will fail.

 

Using this functionality, it is now possible to specify a minimum quantity of VM Compute that is guaranteed to be available.

 

 

What does this look like in production?

  1. Create Capacity Reservation Group with correct quantities
  2. Create the policy definition
  3. Assign the policy to have VMs automatically added
  4. Create Virtual Machines

 

Create Capacity Reservations with correct quantities

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

CraigDuBose_4-1721168491543.png

 

Zonal: CRGRG1-WUS3-z

CraigDuBose_5-1721168491544.png

 

 

Create the policy definition

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.

 

Assign the policy to have VMs automatically added

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

 

 

Create Virtual Machines within the specified context

  • Based on the above, if a VM is created with the SKU E2s_v4 in availability zone 1, it will automatically be added to CRGRG1-WUS3-z.
  • Based on the above, if I create a VM with the SKU E2s_v4 without specifying an availability zone, it will automatically be added to CRGRG1-WUS3-r.

 

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"

      }

    }

 

 

An example copy of the policy can be found below: 

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"

        ]

      }

    }

  }

 

 

Published on:

Learn more
Azure Compute Blog articles
Azure Compute Blog articles

Azure Compute Blog articles

Share post:

Related posts

Azure NetApp Files now stores sensitive data DoD IL5 compliant in Azure US Government regions

Table of Contents Introduction Why Azure NetApp Files? DoD IL5 compliance in Azure Government Azure NetApp Files reaches feature parity betwee...

1 day ago

Enhancements to Azure Monitor Baseline Alerts for Azure Landing Zones

Introduction   Welcome to our latest blog post where we dive into a number of exciting new key updates, highlight the new portal accelera...

1 day ago

Azure Cosmos DB Vector Search with DiskANN Part 1: Full Space Search

Vector Search with Azure Cosmos DB Azure Cosmos DB NoSQL features advanced vector indexing and search capabilities powered by DiskANN, a suite...

2 days ago

Azure Developer CLI (azd) – September 2024

This post announces the September release of the Azure Developer CLI (`azd`). Including remote container build support, multiple hooks per eve...

2 days ago

IBM Power Virtual Server and Microsoft Azure Multi-cloud Integration Patterns

 IBM Power Virtual Server and Microsoft Azure Multi-cloud Integration Patterns               &nbs...

2 days ago

Azure CLI docker container base Linux image is now Azure Linux

Starting from the version  2.64.0 of Azure CLI, the base Linux distribution of Azure CLI is now Azure Linux.   Impact of the change ...

2 days ago

Enhancing Data Security and Digital Trust in the Cloud using Azure Services.

  Introduction Think of Client-Side Encryption (CSE) as a strategy that has proven to be most effective in augmenting data security and ...

2 days ago

Optimizing Azure Table Storage: Automated Data Clean-up using a PowerShell script with Azure Automat

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

2 days ago

Exciting New Features for GitHub Copilot for Azure

We've been on a roll adding new features to the private preview and we've added some of my favorites in our latest release!  Building App...

3 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy