Getting a 401 when trying to start a pod using an image from the registry in AKS

Matthieu Patou 0 Reputation points

I'm trying to deploy a statefulset and I'm getting:

failed to authorize: failed to fetch anonymous token: unexpected status from GET request to 401 Unauthorized

Followed instructions at checked that AKS and ACR are linked but still no success.

az aks check-acr --name my-aks-cluster --resource-group k8s --acr myregistry
The login server endpoint suffix '' is automatically appended.
Merged "my-aks-cluster" as current context in /tmp/tmp3u0o8pus
[2023-11-29T18:19:55Z] Checking host name resolution ( SUCCEEDED
[2023-11-29T18:19:55Z] Canonical name for ACR (
[2023-11-29T18:19:55Z] ACR location: westus2
[2023-11-29T18:19:55Z] Checking managed identity...
[2023-11-29T18:19:55Z] Kubelet managed identity client ID: xxxxxx-xxxx-xxxx-xxxx-xxxxxxx
[2023-11-29T18:19:55Z] Validating managed identity existance: SUCCEEDED
[2023-11-29T18:19:55Z] Validating image pull permission: SUCCEEDED
Your cluster can pull images from!

I'm using AKS with managed identity I haven't specified any user assigned identity.

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
427 questions
Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,988 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Andriy Bilous 11,176 Reputation points MVP

    Hello @Matthieu Patou

    I would recommend you to attach an ACR to an existing AKS cluster comparing to the article

    Azure CLICopyOpen Cloudshell

    # Attach using acr-name
    az aks update -n myAKSCluster -g myResourceGroup --attach-acr <acr-name>
    # Attach using acr-resource-id
    az aks update -n myAKSCluster -g myResourceGroup --attach-acr <acr-resource-id>


    The az aks update --attach-acr command uses the permissions of the user running the command to create the ACR role assignment. This role is assigned to the kubelet managed identity. For more information on AKS managed identities, see Summary of managed identities.