Create a registry credential secret and reference in pod and deployment specs so you can pull container images without errors.
Docker Hub requires an account to pull images from. You can create a Kubernetes secret with your Docker Hub credentials and reference this secret in pods and deployment specs.
This approach can also be used for other private registries.
Procedure
- Run
docker version
and verify that Docker is installed.
- Run
docker login -u USERNAME
.
- Enter your Docker Hub password.
- Run
cat ~/.docker/config.json
.
- Run the following command to create a generic secret named
regcred
that includes your Docker Hub access credentials.
kubectl create secret generic regcred \
--from-file=.dockerconfigjson=/home/ubuntu/.docker/config.json \
--type=kubernetes.io/dockerconfigjson
You should see
secret/regcred created
.
- Verify the secret.
kubectl get secrets
NAME TYPE DATA AGE
default-token-w7wqk kubernetes.io/service-account-token 3 6h28m
regcred kubernetes.io/dockerconfigjson 1 3h22m
Reference the regcred secret in the YAML.
- Reference the
regcred
secret in the imagePullSecrets
section of pod or deployment spec for container images.
For example:
apiVersion: v1
kind: Pod
metadata:
name: ping-pod
namespace: default
spec:
containers:
- image: busybox:1.34
name: busybox
command: ["ping", "-c"]
args: ["1", "8.8.8.8"]
imagePullSecrets:
- name: regcred
restartPolicy: Never