为什么我的部署无法拉取来自GCP Artifact Registry的图像?

huangapple go评论89阅读模式
英文:

Why are images from the GCP Artifact Registry not being pulled by my deployments?

问题

我有两个项目在GCP。我们将它们称为项目A和项目B。项目A将包含部署的集群,而项目B将包含Artifact Registry(请注意,这与Container Registry不同)。

部署正在从Artifact Registry拉取一个Docker镜像。假设Docker镜像是一个标准的Ubuntu镜像,我们的部署正在尝试部署它,假设该镜像已经在Artifact Registry中没有问题。

Ubuntu镜像到集群的部署是通过GitLab CI/CD流水线完成的。它使用具有以下角色的服务帐户:

  • Artifact Registry Reader
  • Kubernetes Engine Developer
  • Viewer

另外,我们还注意到集群具有两个节点池。一个是自定义节点池,另一个是默认的。它们都具有以下访问范围:

cloud-platform范围已启用,以确保节点池可以从位于不同项目中的Artifact Registry中提取。

还要注意,两个节点池都使用具有以下角色的默认服务帐户:

  • Artifact Registry Reader
  • Editor

部署完成后,GitLab流水线完成而没有问题。然而,集群中的部署工作负载失败。发生以下事件:

  1. 拉取镜像“europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest”
  2. 无法拉取镜像“europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest”:rpc错误:代码=Unknown desc=无法拉取和解压镜像“europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest”:无法解析引用“europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest”:授权失败:获取oauth令牌失败:意外状态:403 Forbidden
  3. 错误:ErrImagePull
  4. 错误:ImagePullBackOff
  5. 回退拉取镜像“europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest”

部署的YAML文件如下:

  1. ---
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: ubuntu-build-deploy-demo
  6. labels:
  7. app: ubuntu
  8. namespace: customnamespace
  9. spec:
  10. replicas: 1
  11. selector:
  12. matchLabels:
  13. app: ubuntu
  14. template:
  15. metadata:
  16. labels:
  17. app: ubuntu
  18. spec:
  19. containers:
  20. - name: ubuntu
  21. image: europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest
  22. command: ["sleep", "123456"]

为什么无法正确拉取镜像?为什么尽管具有正确的服务帐户角色和访问范围,但我会收到身份验证问题?如何解决这个问题?

我已经多次检查了镜像名称、标签和路径是否正确。我还确保服务帐户具有正确的角色(前面指定的)。我还确保节点池访问范围是正确的,并确实具有正确的访问范围(前面指定的)。我对如何解决这个问题感到困惑。任何帮助将不胜感激。

英文:

I have two projects in GCP. Let's call them project A and project B. Project A will contain the cluster for the deployment, while project B will contain the Artifact Registry (please note that this is not the same as the Container Registry).

The deployment is pulling a docker image from the Artifact Registry. Let's say the docker image is a stock standard Ubuntu image that our deployment is trying to deploy, and let's assume that the image is already in the Artifact Registry with no issues.

The deployment of the ubuntu image to the cluster is done via a GitLab CI/CD pipeline. It uses a service account that has the following roles:

  • Artifact Registry Reader
  • Kubernetes Engine Developer
  • Viewer

Additionally we also note that the cluster features two node pools. One is a custom node pool and the other is the default. They both have the following access scopes:

The cloud-platform scope is enabled to ensure that the node pools can pull from the Artifact Registry which is in a different project.

It is also important to note that both node pools use the default service account which has the roles:

  • Artifact Registry Reader
  • Editor

Upon deployment, the GitLab pipeline completes with no issues. However, the deployment workload fails in the cluster. The following events occur:

  1. Pulling image "europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest"
  2. Failed to pull image "europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest": rpc error: code = Unknown desc = failed to pull and unpack image "europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest": failed to resolve reference "europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest": failed to authorize: failed to fetch oauth token: unexpected status: 403 Forbidden
  3. Error: ErrImagePull
  4. Error: ImagePullBackOff
  5. Back-off pulling image "europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest"

The deployment YAML file is as follows:

  1. ---
  2. apiVersion: apps/v1
  3. kind: Deployment
  4. metadata:
  5. name: ubuntu-build-deploy-demo
  6. labels:
  7. app: ubuntu
  8. namespace: customnamespace
  9. spec:
  10. replicas: 1
  11. selector:
  12. matchLabels:
  13. app: ubuntu
  14. template:
  15. metadata:
  16. labels:
  17. app: ubuntu
  18. spec:
  19. containers:
  20. - name: ubuntu
  21. image: europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest
  22. command: ["sleep", "123456"]

Why is the image not pulled from correctly? Why am I getting an auth issue despite the correct service account roles and access scopes? How can I resolve this issue?

I have double checked that the image name, tag, and path are correct many times. I have also double checked that the service accounts have the correct roles (specified earlier). I have also ensured that the node pool access scopes are correct and do indeed have the correct access scopes (specified earlier).

I am at a loss of how to resolve this issue. Any help would be greatly appreciated.

答案1

得分: 1

如@avinashjha所说:项目A的默认服务帐户需要在项目B中具有Artifact Registry Reader角色。这允许默认服务帐户从注册表中进行OAuth并拉取Docker镜像。

英文:

Putting in answer form. As @avinashjha said: the default service account from project A needs to have the role Artifact Registry Reader in project B. This allows for the default service account to oauth and pull the docker image from the registry.

huangapple
  • 本文由 发表于 2023年4月19日 17:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76052684.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定