【问题标题】:How to pull/push from/to GCR from GKE node如何从 GKE 节点拉取/推入 GCR
【发布时间】:2021-07-09 14:01:50
【问题描述】:

我正在构建一个将在 GKE 中运行的应用程序。此应用程序将使用 shell 命令(目前)构建 docker 映像并尝试将它们推送到 GCR。我发现当我尝试从 GKE 中运行的 pod 执行此操作时,我遇到了身份验证问题。我无法弄清楚为什么会出现这些身份验证问题。

这里列出了我迄今为止所做的所有调试。在最高级别,我的 GKE 集群具有 https://www.googleapis.com/auth/devstorage.read_write oauth 范围。当我检查底层 GCE 实例的权限时,我看到了这些权限 - 请注意 StorageRead Write 值:

现在,当我使用控制台通过 SSH 连接到该实例并列出 docker 映像时,我会看到 GKE 在启动我的 pod 时使用的映像:

paymahn@gke-prod-478557c-default-pool-e9314f46-d9mn ~ $ docker image ls
REPOSITORY                                                              TAG                 IMAGE ID            CREATED             SIZE
gcr.io/gadic-310112/server                                              latest              8f8a22237c31        2 days ago          1.85GB
...

但是,如果我尝试在 SSH-ed 到 GCP 实例时手动拉取该图像,我会遇到身份验证问题:

paymahn@gke-prod-478557c-default-pool-e9314f46-d9mn ~ $ docker pull gcr.io/gadic-310112/server:latest
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

我还查看了服务帐户65106360748-compute@developer.gserviceaccount.com,它是默认的计算实例服务帐户。以下是它拥有的权限(我手动添加了Storage Object Creator 角色):

Storage Object Creator 角色添加到该服务帐户没有帮助。

我的身份验证方法是否存在根本缺陷?似乎我已经准备好从 GKE 从 GCR 拉/推的所有正确部件。也许我需要为docker 客户端执行额外的步骤来进行身份验证?

【问题讨论】:

  • 你能尝试运行gcloud auth configure-docker吗?

标签: docker google-compute-engine google-kubernetes-engine google-container-registry


【解决方案1】:

想通了。我不得不:

  1. 使用roles/storage.objectAdmin 创建一个服务帐户
  2. 为该服务帐户生成密钥
  3. 将该密钥作为机密存储在 GKE 中
  4. 将该秘密装载到我的 pod 中
  5. 运行gcloud auth activate-service-account --key-file <path to key>
  6. 运行gcloud auth configure-docker

所有这些都完成后,我的 pod 就可以从 GCR 拉出并推送到 GCR。

【讨论】:

    猜你喜欢
    • 2023-04-06
    • 2021-09-30
    • 2021-09-19
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    相关资源
    最近更新 更多