Kubectl 无法从私有 gcr.io 存储库中提取 docker 图像

Kubectl Failed to pull docker image from private gcr.io repo

我在从私有 GCR 中提取 docker 图像时遇到同样的问题,它抛出错误

Failed to pull image "gcr.io/{PROJECT_ID}/{IMAGE:TAG}:latest": rpc error: code = Unknown desc = Error response from daemon: repository gcr.io/{PROJECT_ID}/{IMAGE:TAG} not found: does not exist or no pull access

我尝试过但仍未解决问题的解决方案: 1.删​​除集群重新创建 2. 为拉取镜像的服务账号提供Editor Storage Admin。

另外,当我尝试 docker 使用服务帐户身份验证提取图像时,我能够将图像下载到我的本地

docker image pull gcr.io/{PROJECT_ID}/{IMAGE:TAG}

任何建议\帮助我缺少什么

谢谢

您 运行 是来自您本地计算机的 kubectl 命令吗?
如果是这样,您应该首先使用
配置 GKE 的 kubectl 上下文 gcloud container clusters get-credentials my-cluster --zone=europe-west2-a

在此处阅读更多信息
https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials

在执行上述命令之前,您可能需要安装和配置 Google Cloud SDK。 https://cloud.google.com/sdk/install
https://cloud.google.com/sdk/docs/initializing

这个问题主要出现在我们使用默认服务账户创建集群时(没有从GCR拉取镜像的权限),所以要解决这个问题,我们可以尝试以下方法:

我们需要在创建集群的时候指定scope为cloud-platform,这样集群中的节点才能获取到GCR拉取镜像的权限

gcloud container clusters create "test-cluster"   --zone "us-central1-a"   --machine-type "n1-standard-1"    --scopes https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/devstorage.read_write  --num-nodes "3"

我们可以在创建集群时分配一个服务帐户,该帐户有权从 Google 容器注册表中拉取镜像:

*gcloud container clusters create "test-cluster" --zone "us-central1-a" --machine-type "n1-standard-1" --num-nodes "3" --service-account "XXXXXX@XXXXX.iam.gserviceaccount.com"*

此致

我建议确保您在集群中设置了适当的范围,以便服务帐户可以拉取映像。 Here 是一篇提供有关如何授予用户从注册表中提取映像的权限的分步说明的文章。