我如何在Kubernetes dockerconfigjson中使用Github软件包Docker注册表?

问题描述 投票:0回答:1

如何从Kubernetes集群中提取docker.pkg.github.com Docker映像?

当前,即使对于公共Github存储库中的软件包,Github Docker注册表也要求进行身份验证。

github kubernetes docker-registry
1个回答
0
投票
  1. read:packageshttps://github.com/settings/tokens/new范围创建新的Github个人访问令牌。
  2. Base-64编码<your-github-username>:<TOKEN>,即:

    $ echo -n VojtechVitek:4eee0faaab222ab333aa444aeee0eee7ccc555b7 | base64
    <AUTH>
    

    注意:请确保不要在字符串末尾编码换行符。

  3. 创建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/sopshttps://github.com/bitnami-labs/sealed-secrets之类的工具加密/密封文件。

  4. 现在,您可以通过imagePullSecrets字段从pod的规范定义中引用上述秘密:

    spec:
      containers:
      - name: your-container-name
        image: docker.pkg.github.com/<ORG>/<REPO>/<PKG>:<TAG>
      imagePullSecrets:
      - name: dockerconfigjson-github-com
    
© www.soinside.com 2019 - 2024. All rights reserved.