azure - AKS 无法拉取 ACR 图像 ImagePullBackOff

标签 azure azure-aks acr

我使用 Azure Kubernetes 服务从 Azure 容器注册表执行 docker 镜像部署。 部署后我得到:

Failed to pull image "<reg_name>.azurecr.io/service:latest": [rpc error: code = NotFound desc = failed to pull and unpack image "<reg_name>.azurecr.io/service:latest": failed to resolve reference "<reg_name>.azurecr.io/service:latest": <reg_name>.azurecr.io/service:latest: not found, rpc error: code = Unknown desc = failed to pull and unpack image "<reg_name>.azurecr.io/service:latest": failed to resolve reference "<reg_name>.azurecr.io/service:latest": failed to authorize: failed to fetch anonymous token: unexpected status: 401 Unauthorized]

我创建了服务主体并获取了主体名称和密码(基于: https://anupams.net/using-image-pull-secrets-with-azure-container-registry/ ),然后将其放入 kubernetes secret 中。 接下来在我的deployment.yml中,我使用了属性:imagePullSecrets和之前创建的 secret 。但部署后仍然无法工作,并且 kubectl get pods 报告相同的问题:

service-deployment-cbf49bcd9-vs2jz   0/1     ImagePullBackOff   0          27m

我尝试使用“docker login”命令和之前创建的服务主体凭据登录 - 它有效。但在 AKS 中则不然... 谢谢您的帮助。

最佳答案

您应该使用利用 RBAC 的 AKS ACR 集成,而不是使用带有 Kubernetes key 的服务主体。

微软也推荐它:

While pull secrets are commonly used, they bring additional management overhead. If you're using Azure Kubernetes Service, we recommend other options such as using the cluster's managed identity or service principal to securely pull the image without an additional imagePullSecrets setting on each pod.

您可以通过对现有群集使用 Azure CLI details here 来执行此操作或创建一个新集群 details here 。如果您使用 Terraform 或 Bicep,您还可以自行创建角色分配。

地形示例:

 resource "azurerm_role_assignment" "example" {
    scope                            = azurerm_container_registry.acr.id
    role_definition_name             = "AcrPull"
    principal_id                     = azurerm_kubernetes_cluster.aks.kubelet_identity[0].object_id
  } 

关于azure - AKS 无法拉取 ACR 图像 ImagePullBackOff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74754046/

相关文章:

python - 无法使用 Python 创建 Azure 表

azure - Kubernetes 中出现 "containers with unready status: []"错误

azure - AKS 模板创建新资源组

azure - 网/http : TLS handshake timeout while login to Azure container registry from ubuntu

azure - 无法授予对 VisualStudio.com GIT 存储库的访问权限

java - 使用 odata4j 的 Bing 搜索 API 错误

azure - 尝试访问已部署的函数时,KUDU 给出禁止错误 - 403

Azure AKS 主节点架构

Azure 容器注册表保留策略

azure - 尽管 `az acr login` 显示 ACR 运行正常,但 Windows 中的 `az acr health-check` 超时