Skip to main content
In this lab you will configure Kubernetes to pull images from a private Docker registry by creating a 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 the docker-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 the web Deployment to see the container image currently in use:
Example relevant excerpt from the Deployment’s pod template (trimmed for clarity):

2) Update the Deployment to use a private registry image

Change the container image to reference the private registry at myprivateregistry.com:5000. Update the pod template to use:
Apply this change (for example with 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:
Typical output showing the problem:
The pod events will show an image pull error (unauthorized or failed response) indicating credentials are required.

3) Create a docker-registry Secret with your registry credentials

Create a docker-registry Secret that Kubernetes can use to authenticate to myprivateregistry.com:5000:
This command creates a Secret named private-reg-cred in the current namespace.

4) Reference the Secret in the Deployment using imagePullSecrets

You must add the Secret under the pod spec (not inside a container). Patch the Deployment pod template to include imagePullSecrets:
Add this by editing the Deployment:
When you save the Deployment, the controller will perform another rolling update and attempt to pull images using the provided credentials. Monitor rollout progress:
Example pod status after a successful image pull:
You should see the old pods terminate as new pods successfully reach the 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.
  • imagePullSecrets must be placed under the pod spec (.spec.template.spec.imagePullSecrets for Deployments).
  • The secret name referenced in imagePullSecrets must 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.

Watch Video