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

Upcoming Changes to Instance Size Flexibility Ratios for Reserved VM Instances for M-series: What Yo

Overview In the ever-evolving landscape of cloud computing, it is crucial to stay informed about changes that may affect your usage and busine...

1 year ago

Exploring SUSE Enterprise Linux on Azure

Exploring SUSE Enterprise Linux on Azure In today's cloud-centric world, leveraging robust and reliable operating systems is crucial for busin...

1 year ago

Announcing Public Preview of new attach/detach disks API for VMs/VMSS

We are excited to announce the public preview of a new API that will make attaching and detaching disks to a VM faster and easier. The new API...

1 year ago

Fine-tuning a Hugging Face Diffusion Model on CycleCloud Workspace for Slurm

Introduction Azure CycleCloud Workspace for Slurm (CCWS) is a new Infrastructure as a Service (IaaS) solution which allows the users to purpos...

1 year ago

Public Preview Announcement-On Demand Capacity Reservation in Azure in China

Today, we're announcing the public preview of on demand capacity reservations for Azure Virtual Machines in Azure in China Cloud . Y...

1 year ago

Breaking change for Window Server 2022 Image Users with .NET 6

Azure Marketplace media images for Windows Server 2022 currently include .NET 6, but going forward will not include a .NET version with the im...

1 year ago

Announcing the public preview of the new Azure FXv2-series Virtual Machines

Today, Microsoft is announcing the public preview of the new Azure FXv2-series Virtual Machines (VMs), based on the 5th Generation Intel® Xeon...

1 year ago

Effortlessly Migrate Azure VMs between zones

For various reasons you might come across a situation when you need to migrate your Azure VMs from one zone to another. Migrating Azure VMs be...

1 year ago

Announcing Public Preview of Instance Mix on Virtual Machine Scale Sets

Today, we’re excited to announce that the ability to specify multiple different VM sizes in your Virtual Machine Scale Sets (VMSS) with Flexib...

1 year ago

Announcing General Availability of Attach & Detach of Virtual Machines on Virtual Machine Scale Sets

Today, we’re thrilled to announce that the ability to attach or detach Virtual Machines (VMs) to and from a Virtual Machine Scale Set (VMSS) w...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.