Py学习  »  docker

使用docker stack deploy启动时在Kubernetes中使用私有注册表docker映像

kosta • 4 年前 • 281 次点击  

我有一个简单的 docker-compose

version: "3.7"
services: 
  mongo:
    image: asia.gcr.io/myproj/mymongo:latest
    hostname: mongo
    volumes: 
      - type: bind
        source: $MONGO_DB_DATA
        target: /data/db
    command: [ "--bind_ip_all", "--replSet", "rs0", "--wiredTigerCacheSizeGB", "1.5"]

我用下面的命令在Kubernetes启动它

docker-compose config | docker stack deploy    --orchestrator kubernetes --compose-file - mystack

但是,当pod因这个错误而失败时

Failed to pull image "asia.gcr.io/myproj/mymongo:latest": rpc error: code = Unknown desc = Error response from daemon: unauthorized: You don't have the needed permissions to perform this operation, and you may have invalid credentials. To authenticate your request, follow the steps in: https://cloud.google.com/container-registry/docs/advanced-authentication

我的私人注册表是gcloud。我已经使用服务帐户密钥文件按如下方式登录docker。

docker login  -u _json_key -p "$(cat keyfile.json)" https://asia.gcr.io

docker-compose pull

从这个链接 https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ ,我发现我需要创造 ImagePullSecrets

  1. 我怎么能写 ImagePullSecrets公司 我的docker中的语法组合,以便正确引用它。

  2. 链接中提到的方法要求您使用 .docker/config.json

    “授权”:{ “asia.gcr.io”:{}, }, 它不包括用户名和密码,因为我使用keyfile配置了它。我该怎么做?

  3. 或者有什么更简单的方法可以做到这一点?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55259
 
281 次点击  
文章 [ 1 ]  |  最新文章 4 年前
kosta
Reply   •   1 楼
kosta    4 年前

我解决了这个问题,首先创造了这样一个秘密

kubectl create secret docker-registry regcred --docker-server https://<docker registry>  --docker-username _json_key --docker-password <json key> --docker-email=<email>

然后将其添加到默认服务帐户

kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "regcred"}]}'