Virtualization

Kubernetes pods ImagePullBackOff after rotating registry credentials: namespace secret exists but serviceaccount not bound

nordicbyte
1mo ago
Environment

Environment

Kubernetes 1.22 cluster on managed control plane; private Docker registry requiring dockerconfigjson pushed to namespace as a secret. A credential rotation ran and new secret created; pods now report ImagePullBackOff.

Symptoms

Symptoms

New pod creations immediately fail with ImagePullBackOff and 'pull access denied' in events. kubectl describe pod shows image pull error from registry. Existing running pods continue to run until restarted.

Observations

Observations

kubectl get secret -n app ns-registry-secret shows data.dockerconfigjson present. The deployment spec does not reference imagePullSecrets, and the namespace default serviceaccount had the old imagePullSecrets annotation before rotation. ServiceAccount shows no imagePullSecrets entries. Manual kubectl create secret docker-registry and then restarting pods did not fix; recreating pods with imagePullSecrets set in pod spec pulls fine.

Already attempted

Already attempted

Tried adding imagePullSecrets to Deployment spec and force-redeploy; that fixed new pods. Tried patching the default serviceaccount to include imagePullSecrets but pods still failed until the serviceaccount token got refreshed (recreation helped).

Question

Question

What's the safest way to rotate registry credentials across a namespace so existing and new pods can be pulled without manual edits to every Deployment? How to ensure serviceaccount bindings pick up the new secret immediately?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Secret exists but not referenced by serviceaccount and pods lack imagePullSecrets in spec — Kubernetes won't auto-use namespace secrets 90%
ServiceAccount was patched but pods still reference old cached token; pods need to be recreated or serviceaccount token refreshed 55%
Secret type is wrong (not kubernetes.io/dockerconfigjson) or dockerconfigjson is malformed, causing auth failures 30%

Summary

Kubernetes will use imagePullSecrets from the pod spec or the serviceaccount bound to the pod. Creating a secret in the namespace does not automatically attach it to serviceaccounts or pods. The likely root causes: the default serviceaccount still references the old secret and pods created before serviceaccount patch retain the old token; Deployments without imagePullSecrets will not use new secret unless the serviceaccount is updated. ServiceAccount tokens and pod image pull logic may cache references until pods are recreated. The working fix is to patch the serviceaccount to reference the new secret and recreate pods or rollout the deployment.

Suggested Fixes

Diagnostic step 1
Verify secret type and content: kubectl get secret -n <ns> <secret> -o yaml and confirm type: kubernetes.io/dockerconfigjson and valid data.dockerconfigjson.
Diagnostic step 2
Patch the serviceaccount(s) used by your deployments to include the new secret: kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "ns-registry-secret"}]}' -n <ns>.
Diagnostic step 3
Trigger a rollout restart for deployments so pods are recreated and pick up updated serviceaccount: kubectl rollout restart deployment/<name> -n <ns>.

Continue troubleshooting

Matched from the title, description and tags