简体   繁体   English

使用PowerShell ARM Cmdlet授予AKS访问ACR的权限

[英]Grant AKS access to ACR using PowerShell ARM Cmdlets

I am working on to authenticate with Azure Container Registry from Azure Kubernetes Service using PowerShell by following this link . 我正在通过以下链接通过PowerShell使用Azure Kubernetes Service从Azure容器注册表进行身份验证。

This is the code I run in the PowerShell. 这是我在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

The above code contains Azure CLI commands but I want to use PowerShell ARM cmdlets instead of Azure CLI commands. 上面的代码包含Azure CLI命令,但我想使用PowerShell ARM cmdlet代替Azure CLI命令。

You could try the command below, it works fine on my side. 您可以尝试下面的命令,它对我而言很好用。

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有使用 Azure 容器注册表 (ACR) 使用 ARM 模板创建 Azure AKS 集群的选项 - No option to Create Azure AKS cluster with Azure container registry (ACR) using ARM template 在TFS发行管理器上使用AzureAD PowerShell CmdLets - Using AzureAD PowerShell CmdLets on TFS Release Manager 使用Powershell cmdlet的Azure网站自动化 - Azure Website Automation using powershell cmdlets Azure SQL 使用 PowerShell 和 ServicePrincipal 为 AD 用户授予访问权限 - Azure SQL Grant Access for AD User using PowerShell and ServicePrincipal 将容器从 ACR 部署到 AKS - Deploying a container from ACR to AKS 授予Azure Function对ARM REST API的访问权限 - Grant Azure Function access to ARM REST API Azure Powershell cmdlet失败 - Azure Powershell cmdlets fails 对于自动化帐户,使用 azure 资源图是否比 powershell cmdlet 更快? - For automation accounts, is using the azure resource graph faster than powershell cmdlets? 有什么办法可以使用Powershell cmdlet运行datafactory slice - Is there any way to run the datafactory slice using powershell cmdlets 无法使用Powershell cmdlet将Azure Scaleset连接到Automation DSC - Cannot wire up Azure Scaleset to Automation DSC using powershell cmdlets
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM