【问题标题】:Grant AKS access to ACR using PowerShell ARM Cmdlets使用 PowerShell ARM Cmdlet 授予 AKS 对 ACR 的访问权限
【发布时间】:2018-09-08 11:28:43
【问题描述】:

我正在努力通过遵循此link 使用 PowerShell 从 Azure Kubernetes 服务向 Azure Container Registry 进行身份验证。

这是我在 PowerShell 中运行的代码。

#Sign in using Interactive Mode using your login credentials
az login

#Set the current azure subscription
az account set --subscription 'XXXXXXXXXXXXXXXXXXXXXXX'

#See your current azure subscription
#az account show

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

# Get the ACR registry resource id
$ACR_NAME = "XXWEAKSRESSBDEVACR01"
$ACR_RESOURCE_GROUP = "XXWE-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

以上代码包含 Azure CLI 命令,但我想使用 PowerShell ARM cmdlet 而不是 Azure CLI 命令。

【问题讨论】:

  • 你尝试了什么,什么不起作用?
  • 上述脚本工作文件,但我想要 PowerShell ARM 命令而不是 Azure CLI 命令。

标签: azure powershell azure-resource-manager azure-container-service azure-container-registry


【解决方案1】:

你可以试试下面的命令,对我来说效果很好。

Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId "xxxxxxxxxxxxxxxxx"
#Get the id of the service principal configured for AKS
$aks = Get-AzureRmResource -ResourceGroupName "<ResourceGroupName>" -ResourceType Microsoft.ContainerService/managedClusters -ResourceName "<aksname>" -ApiVersion 2018-03-31
$clientid = $aks.properties.servicePrincipalProfile.clientId
#Get the ACR registry resource id
$acr = Get-AzureRmContainerRegistry -ResourceGroupName "<ResourceGroupName>" -Name "<ACRregistryname>" 
$resourceid = $acr.id
#Create role assignment
New-AzureRmRoleAssignment -ApplicationId $clientid -RoleDefinitionName "Reader" -Scope $resourceid

【讨论】:

  • 感谢@Joy,您节省了我宝贵的时间,上面的 PS 脚本运行良好。
猜你喜欢
  • 2020-05-15
  • 2020-01-04
  • 2020-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多