Create Kubernetes Docker Registry secret
$ kubectl create secret docker-registry <secret_name> \
--docker-server=<registry_url> \
--docker-username=<username> \
--docker-password=<password>
# example
$ kubectl create secret docker-registry my-registry-secret \
--docker-server=https://ghcr.io \
--docker-username=xxxx \
--docker-password=yyyy
# .dockerconfig
{
"auths": {
"<REGISTRY_URL>": {
"auth": "$(echo "<USERNAME>:<PASSWORD>" | base64)\"
}
}
}
# example
$ echo "{\"auths\": {\"https://ghcr.io\": {\"auth\": \"$(echo "xxx:yyy" | base64)\"}}}" | base64 | base64
...
# base64
ZXlKaGRYUm9jeUk2SUhzaWFIUjBjSE02THk5bmFHTnlMbWx2SWpvZ2V5SmhkWFJvSWpvZ0ltVklh
RFJQYm13MVpWRnZQU0o5ZlgwSwo=
# secret.yml
apiVersion: v1
data:
.dockerconfigjson: <output_base64>
kind: Secret
metadata:
name: <secret_name>
namespace: <namespace_name>
type: kubernetes.io/dockerconfigjson
$ kubectl apply -f secret.yml
...
secret/<secret_name> created
---
$ kubectl get secret
NAME TYPE DATA AGE
....
demo-registry kubernetes.io/dockerconfigjson 1 23m