Home / Azure

AzureTroubleshootingAdvanced

Sev1: AKS pods stuck in ContainerCreating. Key Vault CSI secret mount failed

New AKS pods hang in ContainerCreating with MountVolume.SetUp failed from secrets-store.csi.k8s.io. Read the error, fix identity, network or secret state in Key Vault, and get rollouts moving again.

Deepak Bhardwaj6 min read

Applies toAzure Kubernetes Service with the Azure Key Vault Secrets Provider add-on (Secrets Store CSI Driver), workload identity or kubelet/add-on managed identity, Azure Key Vault (RBAC or access policies)

Symptoms

  • New pods stay in ContainerCreating. Pods that were already running keep working, so the outage starts when something creates pods: a deployment, a node upgrade, autoscaling or an eviction.
  • kubectl describe pod shows an event like:
Warning  FailedMount  MountVolume.SetUp failed for volume "secrets-store-inline" :
rpc error: code = Unknown desc = failed to mount secrets store objects for pod orders/orders-api-7d9f...,
err: rpc error: code = Unknown desc = failed to mount objects, error: failed to get objectType:secret, objectName:db-password ...
  • The tail of that message tells you which layer failed. Read the whole event before changing anything.

Warning

Don't scale down or restart running pods while you investigate. They already have their secrets mounted; replacement pods will hit the same mount failure and you lose capacity.

1. Get the exact error (3 minutes)

kubectl get pods -n orders --field-selector=status.phase=Pending
kubectl describe pod <pod> -n orders | sed -n '/Events:/,$p'
kubectl get events -n orders --field-selector reason=FailedMount --sort-by=.lastTimestamp | tail -20

Then the provider and driver logs on the node that runs the pod:

node=$(kubectl get pod <pod> -n orders -o jsonpath='{.spec.nodeName}')

kubectl get pods -n kube-system -o wide -l app=csi-secrets-store-provider-azure --field-selector spec.nodeName=$node
kubectl logs -n kube-system <provider-pod-on-that-node> --tail=100

kubectl get pods -n kube-system -o wide -l app=secrets-store-csi-driver --field-selector spec.nodeName=$node
kubectl logs -n kube-system <driver-pod-on-that-node> -c secrets-store --tail=100 | grep '^E'

Pod labels can differ between the add-on and a Helm install; kubectl get pods -n kube-system | grep -i secrets finds them either way.

2. Map the error to the cause

Error text contains Cause Fix
StatusCode=403 / Forbidden / does not have secrets get permission Identity lost its Key Vault role or access policy Step 3a
ForbiddenByFirewall / Client address is not authorized Key Vault firewall or public access change Step 3b
context deadline exceeded / DeadlineExceeded / no such host Network or DNS path to the vault (private endpoint) broken Step 3b
SecretNotFound / StatusCode=404 / is currently in a deleted but recoverable state Secret, key, cert or version deleted, renamed or disabled Step 3c
AADSTS700016, AADSTS70021, AADSTS700213 Workload identity: wrong client ID, or federated credential missing or not matching Step 3d
failed to get secretproviderclass ... not found SecretProviderClass missing or in a different namespace Step 3e
driver name secrets-store.csi.k8s.io not found Driver DaemonSet not running on that node Step 3e

3. Fix

3a. Restore Key Vault permissions

Find which identity the SecretProviderClass uses:

kubectl get secretproviderclass -n orders -o yaml | grep -E 'keyvaultName|clientID|userAssignedIdentityID|usePodIdentity|useVMManagedIdentity|tenantId'
az aks show -g rg-aks -n aks-prod --query "addonProfiles.azureKeyvaultSecretsProvider.identity.clientId" -o tsv

clientID means workload identity; userAssignedIdentityID means a managed identity on the nodes (often the add-on identity above).

For an RBAC-enabled vault, grant read on secrets at the vault scope:

kv_id=$(az keyvault show -n kv-orders-prod --query id -o tsv)
principal=$(az identity list --query "[?clientId=='<client-id>'].principalId" -o tsv)

az role assignment list --scope $kv_id --assignee $principal -o table
az role assignment create --role "Key Vault Secrets User" --assignee-object-id $principal \
  --assignee-principal-type ServicePrincipal --scope $kv_id

Use Key Vault Certificate User for certificates and Key Vault Crypto User for keys. For a vault using access policies:

az keyvault set-policy -n kv-orders-prod --object-id $principal --secret-permissions get

Role assignments can take a few minutes to apply. Check the activity log for who removed the original assignment so it doesn't get removed again by IaC.

3b. Restore the network path

az keyvault show -n kv-orders-prod \
  --query "{public:properties.publicNetworkAccess, default:properties.networkAcls.defaultAction, subnets:properties.networkAcls.virtualNetworkRules[].id, ips:properties.networkAcls.ipRules[].value}" -o json
  • With a private endpoint, resolve the vault from a node and expect a private IP:
kubectl debug node/$node -it --image=busybox:1.36 -- nslookup kv-orders-prod.vault.azure.net
  • With public access plus firewall rules, add the AKS node subnet back as a virtual network rule (the subnet needs the Microsoft.KeyVault service endpoint) or the cluster egress IP:
az keyvault network-rule add -n kv-orders-prod --subnet <aks-node-subnet-id>
az keyvault network-rule add -n kv-orders-prod --ip-address <egress-public-ip>/32

3c. Bring the secret back

az keyvault secret show --vault-name kv-orders-prod -n db-password --query "{enabled:attributes.enabled, exp:attributes.expires, ver:id}" -o json
az keyvault secret list-deleted --vault-name kv-orders-prod --query "[].name" -o tsv
az keyvault secret recover --vault-name kv-orders-prod -n db-password        # deleted
az keyvault secret set-attributes --vault-name kv-orders-prod -n db-password --enabled true   # disabled

If the SecretProviderClass pins objectVersion to a version that was disabled, either re-enable that version or clear objectVersion so it uses the latest, then reapply it.

3d. Fix workload identity

az identity federated-credential list -g rg-identity --identity-name id-orders-prod -o table
kubectl get sa orders-api -n orders -o jsonpath='{.metadata.annotations}'
az aks show -g rg-aks -n aks-prod --query "oidcIssuerProfile.issuerUrl" -o tsv

The federated credential's issuer must equal the cluster's issuer URL, and its subject must be system:serviceaccount:orders:orders-api. Recreate it if the identity or cluster was rebuilt:

az identity federated-credential create -g rg-identity --identity-name id-orders-prod -n orders-api-fic \
  --issuer "<issuer-url>" --subject system:serviceaccount:orders:orders-api --audiences api://AzureADTokenExchange

3e. Driver or SecretProviderClass missing

kubectl get secretproviderclass -A
kubectl get csidriver secrets-store.csi.k8s.io
az aks show -g rg-aks -n aks-prod --query "addonProfiles.azureKeyvaultSecretsProvider.enabled"

If the add-on was disabled, enable it again:

az aks enable-addons -g rg-aks -n aks-prod --addons azure-keyvault-secrets-provider

4. Get pods moving

Pods retry the mount on their own, but the backoff grows. Once a test pod mounts successfully, delete the stuck ones so they're recreated straight away:

kubectl delete pod -n orders --field-selector=status.phase=Pending
kubectl rollout status deployment/orders-api -n orders

Tip

If you sync the secret into a Kubernetes Secret with secretObjects, that Secret only exists while at least one pod mounts the volume. Apps reading it through envFrom fail too until a pod mounts successfully.

Verify recovery

  • No FailedMount events in the last 10 minutes.
  • Provider logs show no new errors.
  • Deployments show all replicas available, and a test rollout on one deployment completes.

Prevent it next time

  • Define Key Vault role assignments, federated credentials and network rules in the same IaC as the cluster so one isn't removed without the other.
  • Alert on Microsoft.Authorization/roleAssignments/delete and Microsoft.KeyVault/vaults/write for production vaults.
  • Alert on pods in ContainerCreating for more than 5 minutes, and on FailedMount events from Container Insights.
  • Turn on secret rotation (az aks addon update -g rg-aks -n aks-prod --addon azure-keyvault-secrets-provider --enable-secret-rotation) and don't pin objectVersion unless you have a reason to.
  • Test a node pool upgrade in staging after any Key Vault change. Upgrades replace every pod and show mount failures straight away.