Skip to content

Commit eb8d3bf

Browse files
authored
Merge pull request #1812 from jkyamog/main
Add another cause for 401 Unauthorized error
2 parents 074a0c4 + 3bff1a8 commit eb8d3bf

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

support/azure/azure-kubernetes/extensions/cannot-pull-image-from-acr-to-aks-cluster.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Can't pull images from Azure Container Registry to Kubernetes
33
description: This article helps you troubleshoot the most common errors that you may encounter when pulling images from a container registry to an AKS cluster.
4-
ms.date: 11/01/2024
4+
ms.date: 03/25/2025
55
author: genlin
66
ms.author: genli
77
ms.reviewer: chiragpa, andbar, v-weizhu, v-leedennis
@@ -58,6 +58,8 @@ The following sections help you troubleshoot the most common errors that are dis
5858

5959
## Cause 1: 401 Unauthorized error
6060

61+
### <a id="cause1a"></a>Cause 1a: 401 Unauthorized error due to incorrect authorization
62+
6163
An AKS cluster requires an identity. This identity can be either a managed identity or a service principal. If the AKS cluster uses a managed identity, the kubelet identity is used for authenticating with ACR. If the AKS cluster is using as an identity a service principal, the service principal itself is used for authenticating with ACR. No matter what the identity is, the proper authorization that's used to pull an image from a container registry is necessary. Otherwise, you may get the following "401 Unauthorized" error:
6264

6365
> Failed to pull image "\<acrname>.azurecr.io/\<repository\:tag>": [rpc error: code = Unknown desc = failed to pull and unpack image "\<acrname>.azurecr.io/\<repository\:tag>": failed to resolve reference "\<acrname>.azurecr.io/\<repository\:tag>": failed to authorize: failed to fetch oauth token: **unexpected status: 401 Unauthorized**
@@ -70,7 +72,7 @@ Several solutions can help you resolve this error, subject to the following cons
7072

7173
- Solutions [5][cause1-solution5] and [6][cause1-solution6] are applicable for the Kubernetes method of [pulling a Kubernetes secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/).
7274

73-
### Solution 1: Make sure AcrPull role assignment is created for identity
75+
#### Solution 1: Make sure AcrPull role assignment is created for identity
7476

7577
The integration between AKS and Container Registry creates an AcrPull role assignment at container registry level for the AKS cluster's kubelet identity. Make sure that the role assignment is created.
7678

@@ -92,7 +94,7 @@ If the AcrPull role assignment isn't created, create it by [configuring Containe
9294
az aks update -n <myAKSCluster> -g <myResourceGroup> --attach-acr <acr-resource-id>
9395
```
9496

95-
### Solution 2: Make sure service principal isn't expired
97+
#### Solution 2: Make sure service principal isn't expired
9698

9799
Make sure that the secret of the service principal that's associated with the AKS cluster isn't expired. To check the expiration date of your service principal, run the following commands:
98100

@@ -107,7 +109,7 @@ For more information, see [Check the expiration date of your service principal](
107109

108110
If the secret is expired, [update the credentials for the AKS cluster](/azure/aks/update-credentials).
109111

110-
### Solution 3: Make sure AcrPull role is assigned to correct service principal
112+
#### Solution 3: Make sure AcrPull role is assigned to correct service principal
111113

112114
In some cases, the container registry role assignment still refers to the old service principal. For example, when the service principal of the AKS cluster is replaced with a new one. To make sure that the container registry role assignment refers to the correct service principal, follow these steps:
113115

@@ -128,7 +130,7 @@ In some cases, the container registry role assignment still refers to the old se
128130
129131
1. Compare the two service principals. If they don't match, integrate the AKS cluster with the container registry again.
130132
131-
### Solution 4: Make sure the kubelet identity is referenced in the AKS VMSS
133+
#### Solution 4: Make sure the kubelet identity is referenced in the AKS VMSS
132134
133135
When a managed identity is used for authentication with the ACR, the managed identity is known as the kubelet identity. By default, the kubelet identity is assigned at the AKS VMSS level. If the kubelet identity is removed from the AKS VMSS, the AKS nodes can't pull images from the ACR.
134136
@@ -155,7 +157,7 @@ Because modifications to the AKS VMSS aren't supported, they don't propagate at
155157
az aks update --resource-group <MyResourceGroup> --name <MyManagedCluster>
156158
```
157159

158-
### Solution 5: Make sure the service principal is correct and the secret is valid
160+
#### Solution 5: Make sure the service principal is correct and the secret is valid
159161

160162
If you pull an image by using an [image pull secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/), and that Kubernetes secret was created by using the values of a service principal, make sure that the associated service principal is correct and the secret is still valid. Follow these steps:
161163

@@ -179,7 +181,7 @@ If you pull an image by using an [image pull secret](https://kubernetes.io/docs/
179181

180182
1. Update or re-create the Kubernetes secret accordingly.
181183

182-
### Solution 6: Make sure the Kubernetes secret has the correct values of the container registry admin account
184+
#### Solution 6: Make sure the Kubernetes secret has the correct values of the container registry admin account
183185

184186
If you pull an image by using an [image pull secret](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/), and that Kubernetes secret was created by using values of [container registry admin account](/azure/container-registry/container-registry-authentication#admin-account), make sure that the values in the Kubernetes secret are the same as the values of the container registry admin account. Follow these steps:
185187

@@ -202,6 +204,29 @@ If you pull an image by using an [image pull secret](https://kubernetes.io/docs/
202204
> [!NOTE]
203205
> If a **Regenerate** password operation occurred, an operation that's named "Regenerate Container Registry Login Credentials" will be displayed in the **Activity log** page of the container registry. The **Activity log** has a [90-day retention period](/azure/azure-monitor/essentials/activity-log#retention-period).
204206
207+
### Cause 1b: 401 Unauthorized error due to incompatible architecture
208+
209+
You might encounter a "401 Unauthorized" error even when the AKS cluster identity is authorized (as described in the [Cause 1a: 401 Unauthorized error due to incorrect authorization](#cause1a) section). This issue can happen if the container image in the ACR doesn't match the architecture (such as arm64 versus amd64) of the node running the container. For example, deploying an arm64 image on an amd64 node or vice versa can result in this error.
210+
211+
The error message will appear as follows:
212+
213+
> Failed to pull image "\<acrname>.azurecr.io/\<repository:\tag>": [rpc error: code = NotFound desc = failed to pull and unpack image "\<acrname>.azurecr.io/\<repository:\tag>": no match for platform in manifest: not found, failed to pull and unpack image "\<acrname>.azurecr.io/\<repository\:tag>": failed to resolve reference "\<acrname>.azurecr.io/\<repository\:tag>": failed to authorize: failed to fetch anonymous token: unexpected status from GET request to https://\<acrname>.azurecr.io/oauth2/token?scope=repository%3A\<repository>%3Apull&service=\<acrname>.azurecr.io: 401 Unauthorized]
214+
215+
When diagnosing this issue using the Azure CLI, you might see an unexpected "exec format error" if your system node pool runs a different architecture than the image in the ACR:
216+
217+
```azurecli
218+
az aks check-acr --resource-group <MyResourceGroup> --name <MyManagedCluster> --acr <myacr>.azurecr.io
219+
220+
exec /canipull: exec format error
221+
```
222+
223+
#### Solution: Push images with the correct architecture or push multi-architecture images
224+
225+
To resolve this issue, use one of the following methods:
226+
227+
- Ensure the container images pushed to ACR match the architecture of your AKS nodes (for example, arm64 or amd64).
228+
- Create and push multi-architecture images that support both arm64 and amd64 architectures.
229+
205230
## Cause 2: Image not found error
206231

207232
> Failed to pull image "\<acrname>.azurecr.io/\<repository\:tag>": [rpc error: code = NotFound desc = failed to pull and unpack image "\<acrname>.azurecr.io/\<repository\:tag>": failed to resolve reference "\<acrname>.azurecr.io/\<repository\:tag>": **\<acrname>.azurecr.io/\<repository\:tag>: not found**

0 commit comments

Comments
 (0)