docker-registry and referencing it in a Deployment’s pod spec via imagePullSecrets. This enables Kubernetes to authenticate to private registries when creating Pods.
Which Secret type should you use for Docker registries?
Kubernetes supports multiple Secret types. For authenticating to a Docker registry you must use thedocker-registry Secret type.
Reference: Kubernetes Secret Types
1) Inspect the existing Deployment and its pod template
List Deployments and inspect theweb Deployment to see which image it is currently configured to use:
nginx:alpine), Kubernetes pulls the image from Docker Hub by default.
2) Update the Deployment to use an image from a private registry
Change the container image to point to your private registry. For this lab we’ll usemyprivateregistry.com:5000/nginx:alpine as an example.
Edit the Deployment and update the image:
3) Pods fail image pull due to missing credentials
Because the registry is private, newly created Pods will fail to pull the image unless credentials are provided. Typical failure symptoms includeImagePullBackOff and error messages indicating unauthorized access.
Example error snippet:
4) Create a docker-registry Secret with registry credentials
Create a Secret of type docker-registry that contains the credentials needed to access the private registry. Replace the placeholders with your actual registry server, username, password, and email:
config.json entry that Kubernetes can use to authenticate when pulling images.
5) Configure the Deployment to use the Secret via imagePullSecrets
Add animagePullSecrets entry under the Deployment’s pod spec (spec.template.spec) that references the Secret name (private-reg-cred). This tells Kubernetes to use those credentials when pulling images for Pods created by the Deployment.
Kubernetes example of the pod field:
imagePullSecrets:
imagePullSecrets configuration.
Monitor rollout and pod status:
Running while older replica set Pods are scaled down/terminated. Kubernetes will use the credentials stored in the docker-registry Secret, allowing image pulls from your private registry to succeed.
Note: If you do not specify a registry in the image name (for example, just
nginx:alpine), Kubernetes pulls the image from Docker Hub by default. Use imagePullSecrets in the pod spec to supply credentials for private registries.References and further reading
- Kubernetes: Specifying ImagePullSecrets on a Pod — https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod
- Kubernetes Secrets — https://kubernetes.io/docs/concepts/configuration/secret/
- Docker Hub — https://hub.docker.com/