代码之家  ›  专栏  ›  技术社区  ›  Pradeep

从Azure Kubernetes服务向Azure容器注册表进行身份验证时出现的问题

  •  0
  • Pradeep  · 技术社区  · 7 年前

    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脚本时,就会出现如下图所示的异常。 enter image description here

    Authenticate with Azure Container Registry from Azure Kubernetes Service

    1 回复  |  直到 7 年前
        1
  •  1
  •   Charles Xu    7 年前

    为了命令 az role assignment create ,参数的说明 --assignee

    表示用户、组或服务主体。支持的格式: 对象id、用户登录名或服务主体名。

    但是你使用的是Azure Kubernetes集群的资源Id。所以你得到了错误。

    以及您发布的链接,文档显示了yaml文件中的机密和使用命令创建的机密 kubectl create secret . 这个秘密只用于从Azure容器注册表中提取图像。

    显示错误时,找不到资源组,因此应仔细检查资源组。

    enter image description here

    所以我建议使用CLI命令 az account set --subscription .

    推荐文章