Remove a virtual machine scale set association from a capacity reservation group

Applies to: ✔️ Uniform scale set ✔️ Flexible scale sets

This article walks you through removing a virtual machine scale set association from a capacity reservation group. To learn more about capacity reservations, see the overview of capacity reservations.

Because both the virtual machine (VM) and the underlying capacity reservation logically occupy capacity, Azure imposes some constraints on this process to avoid ambiguous allocation states and unexpected errors.

There are two ways to change an association:

  • Deallocate the virtual machine scale set, change the capacity reservation group property at the scale set level, and then update the underlying VMs.
  • Update the reserved quantity to zero and then change the capacity reservation group property.

Deallocate the virtual machine scale set

The first option is to deallocate the virtual machine scale set, change the capacity reservation group property at the scale set level, and then update the underlying VMs.

For more information about automatic, rolling, and manual upgrades, see Upgrade policies.

  1. Deallocate the virtual machine scale set:

    POST  https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{VMScaleSetName}/deallocate?api-version=2021-04-01
    
  2. Update the virtual machine scale set to remove the association with the capacity reservation group:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{VMScaleSetName}/update?api-version=2021-04-01
    

    In the request body, set the capacityReservationGroup property to null to remove the virtual machine scale set association to the group:

    {
    "location": "eastus",
    "properties": {
        "virtualMachineProfile": {
            "capacityReservation": {
                "capacityReservationGroup":{
                    "id":null    
                }
            }
        }
    }
    }
    

Update the reserved quantity to zero

The second option involves updating the reserved quantity to zero and then changing the capacity reservation group property.

This option works well when the scale set can't be deallocated and when a reservation is no longer needed. For example, you might create a capacity reservation to temporarily assure capacity during a large-scale deployment. After deployment is finished, the reservation is no longer needed.

For more information about automatic, rolling, and manual upgrades, see Upgrade policies.

  1. Update the reserved quantity to zero:

    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:

    {
    "sku": 
        {
        "capacity": 0
        }
    } 
    

    Note that the capacity property is set to 0.

  2. Update the virtual machine scale set to remove the association with the capacity reservation group.

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{VMScaleSetName}/update?api-version=2021-04-01
    

    In the request body, set the capacityReservationGroup property to null to remove the association:

    {
    "location": "eastus",
    "properties": {
        "virtualMachineProfile": {
            "capacityReservation": {
                "capacityReservationGroup":{
                    "id":null
                }
            }
        }
    }
    }
    

Upgrade policies

  • Automatic upgrade: In this mode, the scale set VM instances are automatically dissociated from the capacity reservation group without any further action from you.
  • Rolling upgrade: In this mode, the scale set VM instances are dissociated from the capacity reservation group without any further action from you. However, they're updated in batches with an optional pause time between them.
  • Manual upgrade: In this mode, nothing happens to the scale set VM instances when the virtual machine scale set is updated. You need to individually remove each scale set VM by upgrading it with the latest scale set model.

Next step