Failed to pull image "xx.azurecr.io/xx:latest": rpc error: code = Unknown desc = Error response from daemon: unauthorized: authentication required

Failed to pull image "xx.azurecr.io/xx:latest": rpc error: code = Unknown desc = Error response from daemon: unauthorized: authentication required

我的 ACR 和 AKS 在同一个 Azure 目录中,订阅相同。

在授予 ACR Pull 对我的服务主体的访问权限后,没有任何效果并且仍然出现此错误。

Error :- Failed to pull image "xx.azurecr.io/xx:latest": rpc error: code = Unknown desc = Error response from daemon: Get https://xx.azurecr.io/v2/xx/manifests/latest: unauthorized: authentication required

screenshot of dashboard

从错误消息中可以看出,您没有通过身份验证来拉取 Azure 容器注册表中的映像。

对于 AKS,有两种方法可以获取从 Azure 容器注册表中拉取映像的权限。

一个是给AKS集群使用的服务主体授予权限。您可以在 Grant AKS access to ACR 中获取详细信息。这样,您只需要一个服务主体。

另一个是将权限授予新的服务主体,与AKS使用的服务主体不同。然后,您使用服务主体创建一个秘密以拉取图像。您可以在 Access with Kubernetes Secret.

中获取详细信息

这是两种不同的方式,所以你应该确保你的步骤没有错误。要检查服务主体的角色分配,CLI 命令如下:

az role assignment list --assignee $SP_ID --role acrpull --scope $ACR_ID

SP_ID取决于您使用的方式。

群集的服务主体 运行 因为,不是我认为的主体 was.To 请检查是否遵循以下步骤。

  1. 运行命令"az aks show -n aks-cluster-name -g resource-group-name | grep client"

  2. 运行commad "az ad sp credential list --id " -- 这个命令是检查secret是否关联。

  3. 登录到 Azure 门户。

  4. 导航到 Azure 容器注册表

  5. IAM --> 查看角色分配 --> 检查客户端 ID 是否存在于列表中且至少具有 "AcrPull" 访问权限。如果不授予对 SP 的访问权限。

请在 YAML 中检查我们是否看到正确的身份验证。

这个错误有不同的原因:默认情况下,使用 AKS 群集创建的服务主体在一年后过期。 https://docs.microsoft.com/en-us/azure/aks/update-credentials 上的说明显示了如何更新或创建新主体。