Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Get Azure VM and VM Scale Set recommendations based on workload, performance, and budget needs.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
workflows/capacity-reservation/references/association-disassociation.md
1# Associating and Disassociating VMs/VMSS with a Capacity Reservation Group23## Association Model45```text6Capacity Reservation Group (CRG)7├── Capacity Reservation: Standard_D4s_v5 × 5 (Zone 1)8├── Capacity Reservation: Standard_D4s_v5 × 3 (Zone 2)9└── Capacity Reservation: Standard_E8s_v5 × 2 (Zone 1)1011VM / VMSS12└── capacityReservationGroup.id = <CRG resource ID>13└── Azure auto-matches to a reservation with the right VM size + zone14```1516### Associating VMs1718Set the `capacityReservationGroup` property when creating or updating a VM.1920#### New VM2122```bash23az vm create \24-g <rg> \25-n <vm-name> \26--image <image> \27--size Standard_D4s_v5 \28--zone 1 \29--capacity-reservation-group <crg-id>30```3132#### Existing VM3334Zonal VMs can be associated while running:3536```bash37az vm update -g <rg> -n <vm-name> --capacity-reservation-group <crg-id>38```3940Regional VMs (no zone) must be deallocated first:4142```bash43az vm deallocate -g <rg> -n <vm-name>44az vm update -g <rg> -n <vm-name> --capacity-reservation-group <crg-id>45az vm start -g <rg> -n <vm-name>46```4748### Associating VMSS4950```bash51az vmss create \52-g <rg> \53-n <vmss-name> \54--image <image> \55--vm-sku Standard_D4s_v5 \56--instance-count 5 \57--zones 1 \58--capacity-reservation-group <crg-id>59```6061Existing VMSS can be associated using `az vmss update` similarly to VMs. Regional VMSS must be deallocated first. Zonal VMSS can be associated without deallocating, but this is currently a [Preview feature](https://learn.microsoft.com/en-us/azure/virtual-machines/capacity-reservation-associate-virtual-machine-scale-set).6263## Disassociating from a Capacity Reservation Group6465Both the VM/VMSS and the underlying capacity reservation logically occupy capacity. Azure imposes constraints to avoid ambiguous allocation states, so you cannot simply remove the association while resources are running against it.6667There are three ways to disassociate. The commands below use `az vm` — for VMSS, substitute `az vmss` and add `az vmss update-instances --instance-ids "*"` as a final step when using a **Manual** upgrade policy.6869### Option 1: Deallocate, then remove association7071Best when the VM/VMSS can tolerate downtime.7273```bash74az vm deallocate -g <rg> -n <vm-name>75az vm update -g <rg> -n <vm-name> --capacity-reservation-group None76az vm start -g <rg> -n <vm-name> # optional77```7879### Option 2: Set reserved quantity to zero, then remove association8081Best when the VM/VMSS cannot be deallocated and the reservation is no longer needed.8283```bash84az capacity reservation update \85-g <rg> --capacity-reservation-group <crg> \86-n <reservation-name> --capacity 087az vm update -g <rg> -n <vm-name> --capacity-reservation-group None88```8990### Option 3: Delete the VM/VMSS9192Deleting the resource automatically removes the association. Some latency may occur before the capacity reservation allocation state updates.9394### VMSS Upgrade Policy Behavior9596| Policy | Behavior |97|---------------|------------------------------------------------------------------------|98| **Automatic** | Instances update automatically — no further action needed |99| **Rolling** | Instances update in batches with an optional pause between them |100| **Manual** | You must run `az vmss update-instances --instance-ids "*"` per update |101102## Learn More103104- [Associate a VM to a Capacity Reservation Group](https://learn.microsoft.com/en-us/azure/virtual-machines/capacity-reservation-associate-vm)105- [Remove/disassociate a VM from a Capacity Reservation Group](https://learn.microsoft.com/en-us/azure/virtual-machines/capacity-reservation-remove-vm)106- [Remove/disassociate a VMSS from a Capacity Reservation Group](https://learn.microsoft.com/en-us/azure/virtual-machines/capacity-reservation-remove-virtual-machine-scale-set)107