How do you let Pods pull from a private registry?
knowledge of image-pull secrets.
create a dockerconfigjson Secret with registry creds; reference it via imagePullSecrets on the Pod or ServiceAccount.
What's really being asked
Whether you understand that pulling an image happens in the kubelet before any container runs, so credentials must be available to the kubelet through a specifically typed Secret, not inside the container.
The full answer
You create a Secret of type kubernetes.io/dockerconfigjson, which stores a .dockerconfigjson key containing the registry hostname, username, password, and optionally email, in the same format Docker writes to config.json. The easiest path is kubectl create secret docker-registry regcred with the server, username, and password flags. You then attach it through imagePullSecrets. You can list it directly in a Pod or template spec, but the cleaner pattern is to patch the namespace's ServiceAccount so every Pod that uses that account automatically inherits the pull secret, avoiding per-Pod boilerplate. At pull time the kubelet selects matching credentials by registry host. Secrets are namespaced, so the credential must live in the same namespace as the Pods.
The mistakes people make
Using a generic Opaque Secret and expecting Kubernetes to know it is registry auth. Passing credentials via environment variables, which the kubelet never sees during pull. Embedding credentials in the Dockerfile. Forgetting that the Secret must exist in the consuming namespace.
What usually comes next
How do you avoid repeating imagePullSecrets across Pods? How would you rotate registry credentials? How does this differ on managed clusters that integrate cloud IAM for ECR or GCR?
A concrete example
kubectl create secret docker-registry regcred --docker-server=registry.example.com --docker-username=ci --docker-password=$TOKEN, then kubectl patch serviceaccount default -p '{"imagePullSecrets":[{"name":"regcred"}]}'. Now Pods in that namespace pull private images with no per-Pod changes.
Interview question
Why must private-registry credentials be supplied via a dockerconfigjson Secret and imagePullSecrets rather than container environment variables?
- a.The kubelet pulls the image before any container or its env existsCorrect
- b.Opaque Secrets cannot store passwords
- c.Environment variables are encrypted and slower to read
- d.imagePullSecrets are the only Secrets allowed in a namespace
Why? this is the answer
Image pulling happens in the kubelet before the container starts, so container env vars do not exist yet; the kubelet needs a dockerconfigjson Secret referenced by imagePullSecrets. Env vars are not encrypted and are irrelevant to pull-time auth.
Just read this? Test yourself on what you have been reading.
Read the original → kubernetes.io
- #kubernetes
- #secrets
- #private-registry
- #imagepullsecrets
- #serviceaccount
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.
See open roles