( This document has recently been published. There may still be many typos and code errors. Please let me know. )
Showing simple recipes on how to use various Docker registries with Kubernetes.
Docker registries details are configured in Kubernetes as Secrets. A specific docker-registry type of Secret.
Also examples of encrypting the secrets with Sealed Secrets for a GitOps Flux based cluster.
brew install kubectl
Optional.
brew tap weaveworks/tap;
brew install weaveworks/tap/eksctl
brew install google-cloud-sdk
brew install azure-cli
brew install doctl
Optional.
helm install sealed-secrets
brew install kubeseal
Optional.
brew install jq
Docker Hub now finally offer access tokens.
kubectl create secret docker-registry dockerhub-registry \
--dry-run -o yaml \
--docker-server=https://index.docker.io/v1/ \
--docker-username=YOUR_USERNAME \
--docker-email=YOUR_EMAIL \
--docker-password=YOUR_ACCESS_TOKEN \
> dockerhub-registry.yml
If you do not use GitOps and sealed secrets, dockerhub-registry.yml can now be applied to the cluster.
kubectl apply -f dockerhub-registry.yml
Quay uses robot accounts to access their registry.
kubectl create secret docker-registry quay-registry \
--dry-run -o yaml \
--docker-server=https://quay.io \
--docker-username=USERNAME+ROBOTNAME \
--docker-password=ROBOT_TOKEN \
> quay-registry.yml
If you do not use GitOps and sealed secrets, quay-registry.yml can now be applied to the cluster.
kubectl apply -f quay-registry.yml
For GCR you need a JSON token from GCP's IAM.
Note GCP sometimes changes this flow.
Then we need to create a Kubernetes Secret using the JSON as a one-line data token.
kubectl create secret docker-registry gcr-registry \
--dry-run -o yaml \
--docker-server=https://gcr.io \
--docker-username=_json_key \
--docker-email=[email protected] \
--docker-password=(jq -c . gcp-service-account.json) \
> gcr-registry.yml
--docker-password=(jq -c . gcp-service-account.json)
--docker-password="$(jq -c . gcp-service-account.json)"
If you do not use GitOps and sealed secrets, gcr-registry.yml can now be applied to the cluster.
kubectl apply -f gcr-registry.yml
If you use GitOps, you would want to encrypt the registry secrets before adding only the encrypted files to version control.
kubeseal --fetch-cert \
--controller-namespace=kube-system \
--controller-name=sealed-secrets \
> sealed-secrets-cert.pem
kubeseal --format=yaml \
--cert=sealed-secrets-cert.pem \
< gcr-registry.yml \
> sealed-gcr-registry.yml
git add sealed-gcr-registry.yml;
rm gcr-registry.yml
Please contribute recipes for other registries:
I may eventually add further registry examples myself.
Please fork and send a pull request with recipes. Please also submit PRs to correct any typos, or useful additions.
Hire me for short term advice or long term consultancy. Sponsor me to create more howtos.
Otherwise contact me. Especially for things factually incorrect. Apologies for procrastinated replies.