You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

同项目下GKE Autopilot无法从私有Artifact Registry拉取镜像求助

问题:同项目GKE拉取Artifact Registry镜像出现ImagePullBackOff(403 Forbidden)

据官方文档说明,同项目内的GKE应该无需额外认证即可从Artifact Registry拉取容器镜像,但实际操作时遇到了ImagePullBackOff错误,kubectl describe po显示403 Forbidden。想确认是否存在操作失误或理解偏差,是否需要额外配置认证?

复现步骤

使用Google Cloud Shell操作:

  • 创建Artifact Registry
gcloud artifacts repositories create test \
    --repository-format=docker \
    --location=asia-northeast2
  • 推送示例镜像
gcloud auth configure-docker asia-northeast2-docker.pkg.dev
docker pull nginx
docker tag nginx asia-northeast2-docker.pkg.dev/${PROJECT_NAME}/test/sample-nginx-image
docker push asia-northeast2-docker.pkg.dev/${PROJECT_NAME}/test/sample-nginx-image
  • 创建GKE Autopilot集群
    通过GUI控制台创建,大部分选项默认,仅修改:
    • 集群名称设为test
    • 区域与Registry一致(asia-northeast2)
    • 启用Anthos Service Mesh
  • 部署镜像到GKE
gcloud container clusters get-credentials test --zone asia-northeast2
kubectl run test --image asia-northeast2-docker.pkg.dev/${PROJECT_NAME}/test/sample-nginx-image
  • 检查Pod状态
    执行kubectl describe po test后,得到包含403 Forbidden的错误日志,最终出现ImagePullBackOff错误。

排查与解决方法

1. 检查节点服务账号权限

默认情况下GKE节点使用的服务账号是[PROJECT_NUMBER]-compute@developer.gserviceaccount.com,如果该账号没有被授予Artifact Registry的读取权限,就会触发403错误。执行以下命令授予权限:

# 先获取项目编号
PROJECT_NUMBER=$(gcloud projects describe ${PROJECT_NAME} --format='value(projectNumber)')
# 绑定读取权限
gcloud projects add-iam-policy-binding ${PROJECT_NAME} \
  --member="serviceAccount:${PROJECT_NUMBER}-compute@developer.gserviceaccount.com" \
  --role="roles/artifactregistry.reader"

2. 验证镜像路径正确性

确认镜像确实存在且路径拼写无误,执行以下命令查看Artifact Registry中的镜像列表:

gcloud artifacts docker images list asia-northeast2-docker.pkg.dev/${PROJECT_NAME}/test

对比输出的镜像路径和部署时使用的路径,确保${PROJECT_NAME}已正确替换,标签无拼写错误。

3. 排查Anthos Service Mesh的影响

启用ASM后,可能会对镜像拉取的身份验证流程产生干扰。建议创建一个不启用ASM的测试集群,部署相同镜像验证是否能正常拉取:

  • 如果测试集群正常,说明ASM的配置存在权限拦截,需要检查ASM的服务账号权限或侧车注入规则。
  • 如果测试集群依然报错,排除ASM因素,继续排查其他配置。

4. 确认节点池区域一致性

虽然集群设置为asia-northeast2,但需确保节点池实际部署在该区域。在GKE控制台查看节点池的区域配置,避免因节点跨区域部署导致的权限或网络问题。


内容的提问来源于stack exchange,提问作者akrsum

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 00:35:30