![](/img/trans.png)
[英]Authenticate Google Compute Engine (GCE) to Pull Image from Google Container Registry (GCR)
[英]401 Unauthorized error while trying to pull image from Google Container Registry
我正在使用谷歌容器注册表 (GCR) 来推送和拉取 docker 个图像。 我在 kube.netes 中创建了一个包含 3 个副本的部署。 部署将使用从 GCR 中提取的 docker 图像。
在 3 个副本中,2 个正在拉取图像并运行良好。但是第三个副本显示以下错误并且 pod 的状态仍然是“ImagePullBackOff”或“ErrImagePull”
“无法拉取图像“gcr.io/xxx:yyy”:rpc 错误:代码 = Unknown desc = 拉取和解压图像“gcr.io/xxx:yyy”失败:无法解析引用“gcr.io/xxx: yyy": 意外状态代码:401 未经授权"
我很困惑,为什么只有一个副本显示错误,而其他 2 个副本运行没有任何问题。 谁能澄清一下?
提前致谢!
ImagePullBackOff和ErrImagePull表示容器使用的镜像无法从镜像注册中心加载。
从私有 Container Registry 存储库拉取镜像时,可能会出现401 unauthorized 错误。 要排除错误:
通过kubectl describe pod POD_NAME | grep "Node:"
识别运行 pod 的节点kubectl describe pod POD_NAME | grep "Node:"
通过运行命令验证节点具有存储 scope
gcloud compute instances describe NODE_NAME --zone=COMPUTE_ZONE --format="flattened(serviceAccounts[].scopes)"
节点的访问 scope 应该至少包含以下内容之一:
serviceAccounts[0].scopes[0]: https://www.googleapis.com/auth/devstorage.read_only serviceAccounts[0].scopes[0]: https://www.googleapis.com/auth/cloud-platform
用足够的 scope 重新创建节点所属的节点池,并且不能修改现有节点,必须用正确的 scope 重新创建节点。
通过以下命令使用 gke-default scope 创建一个新的节点池
gcloud container node-pools create NODE_POOL_NAME --cluster=CLUSTER_NAME --zone=COMPUTE_ZONE --scopes="gke-default"
创建一个只有存储 scope 的新节点池
gcloud container node-pools create NODE_POOL_NAME --cluster=CLUSTER_NAME --zone=COMPUTE_ZONE --scopes="https://www.googleapis.com/auth/devstorage.read_only"
有关故障排除过程的更多信息,请参阅链接。
您好,您将为集群设置角色以访问用于拉取和推送的 GCR 图像,您可以看到https://github.com/GoogleContainerTools/skaffold/issues/336
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.