Home / Azure

AzureTroubleshootingIntermediate

AKS Azure Disk volume won't attach: Multi-Attach errors, zone mismatch and max volume count

A stateful pod on AKS is stuck Pending or ContainerCreating because its Azure Disk won't attach. Match the event to the cause and fix it without corrupting data.

Deepak Bhardwaj8 min read

Applies toAKS Linux node pools with the Azure Disk CSI driver (disk.csi.azure.com), dynamic and static persistent volumes

A database or other stateful pod won't start after a node failure, a drain or a deployment. It is stuck in Pending or ContainerCreating, and the events mention a volume. Find the event first, because each message has a different fix and some quick fixes can corrupt the disk.

Find the failing step

NS=prod
POD=postgres-0

kubectl describe pod $POD -n $NS | sed -n '/Events:/,$p'
kubectl get events -n $NS --field-selector involvedObject.name=$POD --sort-by=.lastTimestamp
kubectl get pvc -n $NS

Pending means the scheduler hasn't found a node or the claim isn't bound. ContainerCreating means a node was chosen and the attach or mount is failing.

Event text Cause Fix
Multi-Attach error for volume Disk is still attached to another node, or two pods want it Remove the old pod; see below
cannot be attached to the VM because it is not in the same zone as the VM Zonal disk, pod placed in another zone Schedule into the disk's zone, or use ZRS
volume node affinity conflict Scheduler finds no usable node in the disk's zone Add capacity in that zone
exceed max volume count Data disk limit of the VM size reached More nodes or a larger size
does not have authorization to perform action 'Microsoft.Compute/disks/read' Static disk outside the node resource group Grant the cluster identity access
StorageAccountType UltraSSD_LRS can be used only when additionalCapabilities.ultraSSDEnabled is set Node pool doesn't support ultra disks New pool with --enable-ultra-ssd
applyFSGroup failed Recursive ownership change on a large volume fsGroupChangePolicy: OnRootMismatch
UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY Damaged ext3/ext4 file system Snapshot, then repair; see below

Map the claim to the Azure disk and the node that holds it:

PVC=data-postgres-0
PV=$(kubectl get pvc $PVC -n $NS -o jsonpath='{.spec.volumeName}')
DISK_ID=$(kubectl get pv $PV -o jsonpath='{.spec.csi.volumeHandle}')

az disk show --ids "$DISK_ID" \
  --query "{state:diskState, managedBy:managedBy, zones:zones, sku:sku.name, sizeGb:diskSizeGB}" -o jsonc

kubectl get volumeattachment -o custom-columns='NAME:.metadata.name,PV:.spec.source.persistentVolumeName,NODE:.spec.nodeName,ATTACHED:.status.attached' | grep $PV

If Azure (managedBy) and Kubernetes (VolumeAttachment) name different nodes, a detach is still in progress or someone changed the disk outside Kubernetes.

Caution

Don't detach the disk with the portal or az vmss, and don't remove VolumeAttachment finalizers as a first response. Detaching a disk that is still mounted can corrupt the file system.

Multi-Attach error

Azure Disk volumes are normally ReadWriteOnce, so one node at a time. First find which pods use the claim:

kubectl get pods -n $NS -o wide
kubectl describe pvc $PVC -n $NS | grep -A3 "Used By"

The old pod is running on a healthy node

This usually happens with a Deployment. RollingUpdate starts the new pod before the old one stops, and the new pod lands on another node. Switch to Recreate:

kubectl patch deployment myapp -n $NS --type merge \
  -p '{"spec":{"strategy":{"type":"Recreate","rollingUpdate":null}}}'

Warning

Recreate stops the old pod before starting the new one, so each rollout has downtime. If replicas need the same files at the same time, use Azure Files with ReadWriteMany. If each replica needs its own disk, use a StatefulSet with volumeClaimTemplates.

The old pod is Terminating and the node is healthy

Wait for its grace period, then check for a finalizer or a hung process. Draining cleanly beats forcing it. After a node reboot the error often clears by itself within a few minutes.

The node is dead

Pods on an unreachable node can stay Terminating because the kubelet cannot confirm the stop. Confirm the VM is really off before going further:

kubectl get nodes
NODE_RG=$(az aks show -g rg-aks -n aks-prod --query nodeResourceGroup -o tsv)
az vmss list -g $NODE_RG --query "[].name" -o tsv
az vmss get-instance-view -g $NODE_RG -n <vmss-name> --instance-id <id> \
  --query "statuses[].displayStatus" -o tsv

If it is deallocated or stopped, apply the out-of-service taint. Kubernetes then force-deletes pods that don't tolerate the taint and detaches their volumes right away:

kubectl taint nodes <node-name> node.kubernetes.io/out-of-service=nodeshutdown:NoExecute

# After the pods have moved and the node has recovered
kubectl taint nodes <node-name> node.kubernetes.io/out-of-service=nodeshutdown:NoExecute-

Caution

Never use this taint on a node that may still be running, or is mid-restart. Two writers on one disk means corruption. The same risk applies to kubectl delete pod --force.

Zone mismatch

An LRS disk lives in one zone. Compare it with your nodes:

kubectl get pv $PV -o jsonpath='{.spec.nodeAffinity}'; echo
kubectl get nodes -L topology.kubernetes.io/zone,agentpool
  • No nodes in that zone: scale up a node pool there. A pool that spans several zones doesn't guarantee that the autoscaler adds a node in the zone you need, so per-zone node pools are safer for zonal disks.
  • Nodes exist but are full or tainted: free up CPU or memory, or fix the pod's tolerations and selectors.
  • Static PV without node affinity: recreate the PV object with the correct zone affinity on topology.disk.csi.azure.com/zone, for example westeurope-1. Set reclaim policy to Retain first.
  • StorageClass with volumeBindingMode: Immediate: the disk is created before the pod is scheduled. Use a class with WaitForFirstConsumer.

Check your classes. Defaults for redundancy vary by AKS version and cluster zones, so read your own output:

kubectl get sc -o custom-columns='NAME:.metadata.name,PROVISIONER:.provisioner,SKU:.parameters.skuName,SKU2:.parameters.skuname,BIND:.volumeBindingMode,RECLAIM:.reclaimPolicy,EXPAND:.allowVolumeExpansion'

For disks that must follow a pod between zones, use a ZRS class:

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: premium-zrs-retain
provisioner: disk.csi.azure.com
parameters:
  skuName: Premium_ZRS
reclaimPolicy: Retain
volumeBindingMode: WaitForFirstConsumer
allowVolumeExpansion: true

ZRS disks aren't available in every region. This class affects new claims only.

Max volume count

Each VM size has a data disk limit. Compare the node's allowance with what is attached:

kubectl get csinode -o custom-columns='NODE:.metadata.name,DRIVERS:.spec.drivers[*].name,MAX:.spec.drivers[*].allocatable.count'
kubectl get volumeattachment -o jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}' | sort | uniq -c

Scale the pool out for quick relief, then move to a size with more data disks if stateful density stays high:

az aks nodepool scale -g rg-aks --cluster-name aks-prod -n stateful --node-count 5

If the cluster autoscaler manages the pool, raise its maximum instead of scaling by hand.

Authorization on a static disk

For a disk outside the node resource group, the cluster identity needs access to that disk:

PRINCIPAL=$(az aks show -g rg-aks -n aks-prod --query identity.principalId -o tsv)
az role assignment create --assignee-object-id $PRINCIPAL --assignee-principal-type ServicePrincipal \
  --role Contributor --scope "$DISK_ID"

With a user-assigned cluster identity, identity.principalId is empty; read it from identity.userAssignedIdentities. If the event names an object ID, assign the role to that one. Allow a few minutes for propagation.

Mount fails after a successful attach

Read the CSI driver log on the pod's node:

NODE=$(kubectl get pod $POD -n $NS -o jsonpath='{.spec.nodeName}')
CSI=$(kubectl get pods -n kube-system -l app=csi-azuredisk-node \
  --field-selector spec.nodeName=$NODE -o jsonpath='{.items[0].metadata.name}')
kubectl logs -n kube-system $CSI -c azuredisk --since=30m

For slow ownership changes, set this in the pod spec:

securityContext:
  fsGroup: 2000
  fsGroupChangePolicy: "OnRootMismatch"

For a file system error, take a snapshot before anything else:

az snapshot create -g rg-aks -n snap-postgres-before-fsck --source "$DISK_ID" --incremental true

Warning

Run a read-only check (fsck.ext4 -n) before a repair (fsck.ext4 -f -y), with the workload scaled to zero. For a database, restoring a known good backup is often safer than trusting repaired files.

Confirm the fix

kubectl get pod $POD -n $NS -o wide
kubectl get volumeattachment | grep $PV
kubectl exec -n $NS $POD -- df -h

Expect one attachment, marked attached, on the same node as the pod. Then check the application's own recovery log.

Prevent it next time

  • Use StatefulSets for pods that own a disk, and Recreate for single-replica Deployments with one.
  • Drain nodes before rebooting or stopping them. Don't restart VMSS instances directly.
  • Use ZRS disks, or one node pool per zone with spare capacity.
  • Set reclaimPolicy: Retain on production data. With Delete, removing the claim removes the disk.
  • Alert on pods in ContainerCreating for more than 10 minutes.
  • Back up persistent volumes and rehearse the restore.