#devops #docker #kubernetes
To use images from a private repository on hub.docker.com, you need to add a secret containing the credentials for accessing that repository. This can be done via the
1$ kubectl create secret docker-registry <my-secret-name> \ 2 --docker-server=docker.io \ 3 --docker-username=<your-docker-username> \ 4 --docker-password=<your-docker-password> \ 5 --docker-email=<your-docker-email>
If the secret already exists and you want to update it, you first need to delete it:
1$ kubectl delete secret <my-secret-name>
When you then define a deployment, you can use the
imagePullSecrets option in the deployment yaml to indicate which secret needs to be used to grab the docker image:
1apiVersion: apps/v1 2kind: Deployment 3metadata: 4 name: my-deployment 5 labels: 6 app: my-deployment 7spec: 8 replicas: 1 9 selector: 10 matchLabels: 11 app: my-deployment 12 template: 13 metadata: 14 labels: 15 app: my-deployment 16 spec: 17 containers: 18 - name: my-deployment 19 image: <my-docker-user>/<my-docker-private-repo< 20 imagePullSecrets: 21 - name: <my-secret-name>
The deployment can then be done using the
1$ kubectl apply -f my-deployment.yaml
You can read many more details about this on the kubernetes.io website.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.