簡體   English   中英

從Azure Kubernetes Service使用Azure容器注冊表進行身份驗證時發出的問題

[英]Issue of while Authenticate with Azure Container Registry from Azure Kubernetes Service

我使用Azure門戶創建了Azure Kubernetes服務和Azure容器注冊表。 之后,我可以授予Grant AKS訪問ACR的權限,為此,我使用了以下腳本:

Login-AzureRmAccount
Set-AzureRmContext -SubscriptionID 'XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXX'
#Get the id of the service principal configured for AKS
$AKS_RESOURCE_GROUP = "DSEU2-AKSRES-SB-DEV-RGP-01"
$AKS_CLUSTER_NAME = "DSEU2-AKSRES-SB-DEV-AKS-01"
$CLIENT_ID=$(az aks show --resource-group $AKS_RESOURCE_GROUP --name     $AKS_CLUSTER_NAME --query "servicePrincipalProfile.clientId" --output tsv)

# Get the ACR registry resource id
$ACR_NAME = "DSWEAKSRESSBDEVACR01"
$ACR_RESOURCE_GROUP = "DSWE-AKSRES-SB-DEV-RGP-01"
$ACR_ID=$(az acr show --name $ACR_NAME --resource-group $ACR_RESOURCE_GROUP --query "id" --output tsv)

#Create role assignment
az role assignment create --assignee $CLIENT_ID --role Reader --scope $ACR_ID

每當我運行上述PowerShell腳本時,就會遇到如下圖所示的異常。 在此處輸入圖片說明

對於上述情況,我遵循此文檔: 從Azure Kubernetes Service使用Azure容器注冊表進行身份驗證

對於命令az role assignment create ,使用--assignee參數的描述:

代表用戶,組或服務主體。 支持的格式:對象ID,用戶登錄名或服務主體名稱。

但是,您使用的是Azure Kubernetes群集的資源ID。 所以你得到了錯誤。

和您發布的鏈接一樣,該文檔在yaml文件中顯示了密鑰,以及使用命令kubectl create secret 該機密僅用於從Azure容器注冊表中提取映像。

更新

在顯示ERROR的情況下,找不到資源組,因此您應該仔細檢查資源組。

然后從腳本中使用PowerShell命令登錄並使用CLI執行。 我認為CLI的訂閱不會更改。 因此,您可以檢查您是否在正確的訂閱中。 PowerShell命令將不會更改CLI訂閱。 在此處輸入圖片說明

因此,我建議使用CLI命令az account set --subscription

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM