Hi QuyHoang,
Thank you for reaching out to the Microsoft Q&A platform.
Encountering a 401 Unauthorized error when pulling images from Azure Container Registry (ACR) using a user-assigned managed identity in Azure Kubernetes Service (AKS).
Here are a few steps to troubleshoot and resolve this issue:
verify if the kubelet identity is correctly assigned, run the following command:
az aks show --resource-group <nameofResourcegrp> --name <cluster-name> --query "identityProfile.kubeletidentity"
After confirming the kubelet identity, check if the required role is assigned:
az role assignment list --assignee <your-managed-identity-client-id> --scope /subscriptions/<your-subscription-id>/resourceGroups/<your-resource-group>/providers/Microsoft.ContainerRegistry/registries/<your-acr-name>
Create Role Assignment (if missing) if the role is not assigned, you can create it with:
az role assignment create --assignee <your-managed-identity-client-id> --role AcrPull --scope /subscriptions/<your-subscription-id>/resourceGroups/<your-resource-group>/providers/Microsoft.ContainerRegistry/registries/<your-acr-name>
Update AKS Cluster Ensure the AKS cluster is updated to use the correct managed identity:
az aks update --resource-group <your-resource-group> --name <your-cluster-name> --assign-identity <your-managed-identity-resource-id>
Verify Kubelet Identity for Node Pools to check if the kubelet identity is applied to all node pools, use:
az vmss identity show --resource-group <your-resource-group> --name <your-node-pool-name>
Set Up Diagnostic Settings for ACR Optionally, you can create diagnostic settings for your Azure Container Registry (ACR):
az acr diagnostic-settings create --registry-name <your-acr-name> --logs Read --metrics Read --storage-account <your-storage-account>
If an answer has been helpful, please consider accept the answer and "Upvote" to help increase visibility of this question for other members of the Microsoft Q&A community.
Thank you.