如何从Kubernetes集群中提取docker.pkg.github.com
Docker映像?
当前,即使对于公共Github存储库中的软件包,Github Docker注册表也要求进行身份验证。
read:packages
的https://github.com/settings/tokens/new范围创建新的Github个人访问令牌。Base-64编码<your-github-username>:<TOKEN>
,即:
$ echo -n VojtechVitek:4eee0faaab222ab333aa444aeee0eee7ccc555b7 | base64
<AUTH>
注意:请确保不要在字符串末尾编码换行符。
创建kubernetes.io/dockerconfigjson机密
A)手动创建秘密:
$ echo '{"auths":{"docker.pkg.github.com":{"auth":"<AUTH>"}}}' | kubectl create secret generic dockerconfigjson-github-com --type=kubernetes.io/dockerconfigjson --from-file=.dockerconfigjson=/dev/stdin
B)或者,创建可在kubectl apply -f
中使用的.yml文件:
kind: Secret
type: kubernetes.io/dockerconfigjson
apiVersion: v1
metadata:
name: dockerconfigjson-github-com
stringData:
.dockerconfigjson: {"auths":{"docker.pkg.github.com":{"auth":"<AUTH>"}}}
GitOps注意:我强烈建议不要将上述文件以纯文本格式存储在git存储库中。水化CD管道中的值或使用https://github.com/mozilla/sops或https://github.com/bitnami-labs/sealed-secrets之类的工具加密/密封文件。
现在,您可以通过imagePullSecrets
字段从pod的规范定义中引用上述秘密:
spec:
containers:
- name: your-container-name
image: docker.pkg.github.com/<ORG>/<REPO>/<PKG>:<TAG>
imagePullSecrets:
- name: dockerconfigjson-github-com