βΈοΈ Kubernetes: Fix ImagePullBackOff From a Misplaced Pull Secret
Secrets — including an imagePullSecrets credential for a private registry — are namespace-scoped objects. Creating the pull secret in default because that’s what a quick-start guide showed does nothing for a Deployment actually running in staging, even though kubectl get secret against your current context clearly shows it exists somewhere in the cluster. The kubelet in the pod’s own namespace simply has no such Secret to authenticate with, and the pod sits in ImagePullBackOff with an error message that never mentions namespaces at all.
π The Problem
# kubectl get secret regcred -n default
NAME TYPE DATA AGE
regcred kubernetes.io/dockerconfigjson 1 4d
# kubectl get secret regcred -n staging
Error from server (NotFound): secrets "regcred" not found
# Deployment running in: staging
spec:
imagePullSecrets:
- name: regcred # looked for in 'staging', not 'default'
β Fix: Create the Secret Where the Pod Actually Lives
- Create the pull secret directly in the same namespace as the Pod or Deployment that references it (
kubectl create secret docker-registry ... -n staging) — imagePullSecrets never looks across namespace boundaries. - If multiple namespaces need the same registry credentials, copy the Secret into each namespace explicitly, or use a tool that syncs secrets across namespaces, rather than assuming one cluster-wide Secret will cover every namespace.
- Confirm with
kubectl get secret <name> -n <pod-namespace>specifically — not just against whatever namespace your current context defaults to — before concluding the credential doesn’t exist anywhere.
π¨ Why This Is Dangerous
- Recreating the exact same secret over and over in the wrong namespace, each time convinced it “still isn’t working,” can burn significant troubleshooting time on a problem a single
-nflag would have revealed immediately.
A Secret that exists somewhere in the cluster and a Secret that exists in your Pod’s namespace are two completely different things to the scheduler.
