如何在Kubernetes dockerconfigjson中使用Github软件包Docker注册表? [英] How can I use Github packages Docker registry in Kubernetes dockerconfigjson?
问题描述
如何从Kubernetes集群中提取 docker.pkg.github.com
Docker映像?
How can I pull docker.pkg.github.com
Docker images from within Kubernetes cluster?
当前,即使是公共Github存储库中的软件包,Github Docker注册表也需要进行身份验证。
Currently, the Github Docker registry requires authentication even for packages from public Github repositories.
推荐答案
- 创建新的Github在 https:下具有
read:packages
范围的个人访问令牌。 //library.com/settings/tokens/new 。 -
Base-64编码
<您的github用户名>:< ; TOKEN>
,即:
- Create new Github Personal Access Token with
read:packages
scope at https://github.com/settings/tokens/new. Base-64 encode
<your-github-username>:<TOKEN>
, ie.:
$ echo -n VojtechVitek:4eee0faaab222ab333aa444aeee0eee7ccc555b7 | base64
<AUTH>
注意:请确保不要在字符串末尾编码换行符。 / em>
Note: Make sure not to encode a newline character at the end of the string.
创建kubernetes.io/dockerconfigjson机密
Create kubernetes.io/dockerconfigjson secret
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中使用的.yml文件apply -f
:
B) Or, create .yml file that can be used in kubectl apply -f
:
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/肥皂或 https://github.com/bitnami-labs/sealed-secrets 。
现在,您可以通过 imagePullSecrets $从pod的规范定义中引用上述秘密了c $ c>字段:
Now, you can reference the above secret from your pod's spec definition via imagePullSecrets
field:
spec:
containers:
- name: your-container-name
image: docker.pkg.github.com/<ORG>/<REPO>/<PKG>:<TAG>
imagePullSecrets:
- name: dockerconfigjson-github-com
这篇关于如何在Kubernetes dockerconfigjson中使用Github软件包Docker注册表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!