unable to attach acr with aks

2/11/2021

I have use following command to attach AKS with ACR

az aks create -n myAKSCluster -g myResourceGroup --attach-acr $MYACR

But the error still persist while fetching image. Then I did a little more investigation to find what all service principal ids are attached using following

az aks list

and I get [] empty array list. Any clue what I might be missing?

az role assignment list --assignee <Aks service principal ID> --scope <ACR ID>

-- user269867
azure-aks
azure-devops
kubernetes

1 Answer

2/14/2021

You can first set the subscription using the following command and then can try with further ones to map ACR to AKS

 az account set --subscription

there are two ways to get this sorted

Map the ACR to AKS

CLIENT_ID=$(az aks show --resource-group $AKS_RESOURCE_GROUP --name 
$AKS_CLUSTER_NAME --subscription $SUBSCRIPTION_ID --query "servicePrincipalProfile.clientId" --output tsv)

ACR_ID=$(az acr show --name $ACR_NAME --resource-group $ACR_RESOURCE_GROUP --subscription $SUBSCRIPTION_ID --query "id" --output tsv)

az role assignment create --assignee $CLIENT_ID --role Reader --scope $ACR_ID
-- Tushar Mahajan
Source: StackOverflow