Cuir in eagar

Comhroinn trí


Create a capacity reservation

Applies to: ✔️ Linux VMs ✔️ Windows VMs ✔️ Uniform scale set ✔️ Flexible scale sets

Capacity reservation is always created as part of a capacity reservation group. The first step is to create a group if a suitable one doesn't exist already, and then create reservations. After reservations are successfully created, they're immediately available for use with virtual machines (VMs). The capacity is reserved for your use as long as the reservation isn't deleted.

A well-formed request for a capacity reservation group should always succeed because it doesn't reserve any capacity. It just acts as a container for reservations. However, a request for capacity reservation could fail if you don't have the required quota for the VM series or if Azure doesn't have enough capacity to fulfill the request. Either request more quota or try a different VM size, location, or zone combination.

Capacity reservation creation succeeds or fails in its entirety. For a request to reserve 10 instances, success is returned only if all 10 instances could be allocated. Otherwise, the capacity reservation creation fails.

Considerations

The capacity reservation must meet the following rules:

  • The location parameter must match the location property for the parent capacity reservation group. A mismatch results in an error.
  • The VM size must be available in the target region. Otherwise, the reservation creation fails.
  • The subscription must have available quota equal to or more than the quantity of VMs being reserved for the VM series and for the region overall. If needed, request more quota.
    • As needed to satisfy existing quota limits, you can do single VMs in stages. Create a capacity reservation with a smaller quantity and reallocate that quantity of VMs. This approach frees up quota to increase the quantity reserved and add more VMs. Alternatively, if the subscription uses different VM sizes in the same series, reserve and redeploy VMs for the first size. Then add a reservation to the group for another size and redeploy the VMs for the new size to the reservation group. Repeat the process until it's complete.
    • For scale sets, available quota is required unless the scale set or you delete its VM instances, capacity is reserved, and the scale set instances are added by using reserved capacity. If the scale set is updated by using blue green deployment, then reserve the capacity and deploy the new scale set to the reserved capacity at the next update.
  • Each capacity reservation group can have exactly one reservation for a specific VM size. For example, you can create only one capacity reservation for the VM size Standard_D2s_v3. Attempting to create a second reservation for Standard_D2s_v3 in the same capacity reservation group results in an error. However, you can create another reservation in the same group for other VM sizes, such as Standard_D4s_v3 and Standard_D8s_v3.
  • For a capacity reservation group that supports zones, each reservation type is defined by the combination of VM size and zone. For example, one capacity reservation for Standard_D2s_v3 in Zone 1, another capacity reservation for Standard_D2s_v3 in Zone 2, and a third capacity reservation for Standard_D2s_v3 in Zone 3 are supported.

Check VM sizes that are available for capacity reservation in a region

Before you create a capacity reservation, you can check the VM sizes that are available for the reservation for a particular region.

  1. Open the Azure portal.
  2. In the search bar, enter capacity reservation groups.
  3. Select Capacity reservation groups from the options.
  4. Select Create.
  5. On the Basics tab, create a capacity reservation group:
    1. Select a Subscription.
    2. Select or create a resource group.
    3. Name your group.
    4. Select a region.
    5. Optionally, select Availability zones or allow Azure to choose for you.
  6. Select Next.
  7. On VM size, select See all sizes to check what VM sizes are available for capacity reservation.

Create a capacity reservation

  1. Create a capacity reservation group.

    To create a capacity reservation group, construct the following PUT request on the Microsoft.Compute provider:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/CapacityReservationGroups/{CapacityReservationGroupName}&api-version=2021-04-01
    

    In the request body, include the following parameter:

    { 
      "location":"eastus"
    } 
    

    This group is created to contain reservations for the US East location.

    The group in the following example only supports regional reservations because zones weren't specified at the time of creation. To create a zonal group, pass an extra parameter zone in the request body:

    { 
      "location":"eastus",
      "zones": ["1", "2", "3"] 
    } 
    
  2. Create a capacity reservation.

    To create a reservation, construct the following PUT request on the Microsoft.Compute provider:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/CapacityReservationGroups/{CapacityReservationGroupName}/capacityReservations/{capacityReservationName}?api-version=2021-04-01 
    

    In the request body, include the following parameters:

    { 
      "location": "eastus", 
      "sku": { 
        "name": "Standard_D2s_v3", 
        "capacity": 5 
      }, 
     "tags": { 
            "environment": "testing" 
    } 
    

    The preceding request creates a reservation in the East US location for five quantities of the D2s_v3 VM size.

Check on your capacity reservation

After the capacity reservation is successfully created, it's immediately available for use with VMs.

GET  
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/CapacityReservationGroups/{CapacityReservationGroupName}/capacityReservations/{capacityReservationName}?api-version=2021-04-01
{ 
    "name": "<CapacityReservationName>", 
    "id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/capacityReservationGroups/{CapacityReservationGroupName}/capacityReservations/{CapacityReservationName}", 
    "type": "Microsoft.Compute/capacityReservationGroups/capacityReservations", 
    "location": "eastus", 
    "tags": { 
        "environment": "testing" 
    }, 
    "sku": { 
        "name": "Standard_D2s_v3", 
        "capacity": 5 
    }, 
    "properties": { 
        "reservationId": "<reservationId>", 
         "provisioningTime": "<provisioningTime>", 
         "provisioningState": "Updating" 
    } 
} 

Next step