英文:
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
另外,我们还注意到集群具有两个节点池。一个是自定义节点池,另一个是默认的。它们都具有以下访问范围:
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/servicecontrol
cloud-platform
范围已启用,以确保节点池可以从位于不同项目中的Artifact Registry中提取。
还要注意,两个节点池都使用具有以下角色的默认服务帐户:
- Artifact Registry Reader
- Editor
部署完成后,GitLab流水线完成而没有问题。然而,集群中的部署工作负载失败。发生以下事件:
拉取镜像“europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest”
无法拉取镜像“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
错误:ErrImagePull
错误:ImagePullBackOff
回退拉取镜像“europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest”
部署的YAML文件如下:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu-build-deploy-demo
labels:
app: ubuntu
namespace: customnamespace
spec:
replicas: 1
selector:
matchLabels:
app: ubuntu
template:
metadata:
labels:
app: ubuntu
spec:
containers:
- name: ubuntu
image: europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest
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:
- https://www.googleapis.com/auth/cloud-platform
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring.write
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/servicecontrol
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:
Pulling image "europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest"
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
Error: ErrImagePull
Error: ImagePullBackOff
Back-off pulling image "europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest"
The deployment YAML file is as follows:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ubuntu-build-deploy-demo
labels:
app: ubuntu
namespace: customnamespace
spec:
replicas: 1
selector:
matchLabels:
app: ubuntu
template:
metadata:
labels:
app: ubuntu
spec:
containers:
- name: ubuntu
image: europe-west1-docker.pkg.dev/B/docker-repo/ubuntu:latest
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论