docker-registry Secret and referencing it from a Deployment using imagePullSecrets. This walkthrough preserves the original sequence of actions: inspect the Deployment, update its image to point at the private registry, observe the pull failure, create the Secret, then add imagePullSecrets so pods can successfully pull the image.
Which Secret type is required?
Use thedocker-registry Secret type to store credentials for authenticating to a Docker registry.
Use a
docker-registry Secret when Kubernetes needs to pull images from a private registry. This Secret stores the registry server, username, password (or token), and email address to authenticate image pulls.1) Inspect the current Deployment and image
List Deployments and describe theweb Deployment to see the container image currently in use:
2) Update the Deployment to use a private registry image
Change the container image to reference the private registry atmyprivateregistry.com:5000. Update the pod template to use:
kubectl edit deploy web or by updating the manifest). The Deployment controller will start a rolling update and create a new ReplicaSet. Because the cluster lacks credentials for the private registry, the new pod will fail to pull the image.
Check pod status:
3) Create a docker-registry Secret with your registry credentials
Create adocker-registry Secret that Kubernetes can use to authenticate to myprivateregistry.com:5000:
private-reg-cred in the current namespace.
4) Reference the Secret in the Deployment using imagePullSecrets
You must add the Secret under the podspec (not inside a container). Patch the Deployment pod template to include imagePullSecrets:
Running state with images pulled from the private registry.
Quick reference
Do not store
docker-registry Secrets (or raw credentials) in public Git repositories or in plaintext in version control. Use a secrets management system, encrypted manifests, or a CI/CD secrets store to keep credentials secure.Notes and reminders
- If you do not specify a registry (for example you use
nginx:alpine), Kubernetes (the container runtime) pulls from Docker Hub by default. imagePullSecretsmust be placed under the podspec(.spec.template.spec.imagePullSecretsfor Deployments).- The secret name referenced in
imagePullSecretsmust match the Secret you created. - Secrets are namespaced: ensure the Secret is in the same namespace as the Deployment or reference a properly namespaced Secret.