Skip to content

Commit 6fd91e1

Browse files
committed
Edited Container Registry Integration article
1 parent 1ff3f4a commit 6fd91e1

File tree

1 file changed

+80
-6
lines changed

1 file changed

+80
-6
lines changed

articles/aks/cluster-container-registry-integration.md

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
title: Integrate Azure Container Registry with Azure Kubernetes Service
33
description: Learn how to integrate Azure Kubernetes Service (AKS) with Azure Container Registry (ACR)
44
ms.topic: article
5-
ms.date: 11/16/2022
5+
ms.date: 03/13/2023
66
ms.tool: azure-cli, azure-powershell
77
ms.devlang: azurecli
88
ms.custom: devx-track-azurepowershell, devx-track-azurecli
99
---
1010

1111
# Authenticate with Azure Container Registry from Azure Kubernetes Service
1212

13-
You need to establish an authentication mechanism when using [Azure Container Registry (ACR)][acr-intro] with Azure Kubernetes Service (AKS). This operation is implemented as part of the Azure CLI, Azure PowerShell, and Azure portal experiences by granting the required permissions to your ACR. This article provides examples for configuring authentication between these Azure services.
13+
When using [Azure Container Registry (ACR)][acr-intro] with Azure Kubernetes Service (AKS), you need to establish an authentication mechanism. Configuring the required permissions between ACR and AKS can be accomplished using the Azure CLI, Azure PowerShell, and Azure portal. This article provides examples to configure authentication between these Azure services using the Azure CLI or Azure PowerShell.
1414

15-
You can set up the AKS to ACR integration using the Azure CLI or Azure PowerShell. The AKS to ACR integration assigns the [**AcrPull** role][acr-pull] to the [Azure Active Directory (Azure AD) **managed identity**][aad-identity] associated with the agent pool in your AKS cluster. For more information on AKS managed identities, see [Summary of managed identities][summary-msi].
15+
The AKS to ACR integration assigns the [**AcrPull** role][acr-pull] to the [Azure Active Directory (Azure AD) **managed identity**][aad-identity] associated with the agent pool in your AKS cluster. For more information on AKS managed identities, see [Summary of managed identities][summary-msi].
1616

1717
> [!IMPORTANT]
18-
> There is a latency issue with Azure Active Directory groups when attaching ACR. If the AcrPull role is granted to an Azure AD group and the kubelet identity is added to the group to complete the RBAC configuration, there may be a delay before the RBAC group takes effect. If you are running automation that requires the RBAC configuration to be complete, we recommended you use the [Bring your own kubelet identity][byo-kubelet-identity] as a workaround. You can pre-create a user-assigned identity, add it to the Azure AD group, then use the identity as the kubelet identity to create an AKS cluster. This ensures the identity is added to the Azure AD group before a token is generated by kubelet, which avoids the latency issue.
18+
> There is a latency issue with Azure Active Directory groups when attaching ACR. If the **AcrPull** role is granted to an Azure AD group and the kubelet identity is added to the group to complete the RBAC configuration, there may be a delay before the RBAC group takes effect. If you are running automation that requires the RBAC configuration to be complete, we recommended you use the [Bring your own kubelet identity][byo-kubelet-identity] as a workaround. You can pre-create a user-assigned identity, add it to the Azure AD group, then use the identity as the kubelet identity to create an AKS cluster. This ensures the identity is added to the Azure AD group before a token is generated by kubelet, which avoids the latency issue.
1919
2020
> [!NOTE]
2121
> This article covers automatic authentication between AKS and ACR. If you need to pull an image from a private external registry, use an [image pull secret][image-pull-secret].
@@ -55,6 +55,31 @@ $MYACR = 'myContainerRegistry'
5555
New-AzContainerRegistry -Name $MYACR -ResourceGroupName myContainerRegistryResourceGroup -Sku Basic
5656
```
5757

58+
#### [Terraform](#tab/terraform)
59+
60+
```terraform
61+
# Example Usage
62+
resource "azurerm_container_registry" "acr" {
63+
name = "containerRegistry1"
64+
resource_group_name = azurerm_resource_group.example.name
65+
location = azurerm_resource_group.example.location
66+
sku = "Premium"
67+
admin_enabled = false
68+
georeplications {
69+
location = "East US"
70+
zone_redundancy_enabled = true
71+
tags = {}
72+
}
73+
georeplications {
74+
location = "North Europe"
75+
zone_redundancy_enabled = true
76+
tags = {}
77+
}
78+
}
79+
```
80+
81+
For more information about the syntax and argument reference, see [Terraform reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry).
82+
5883
---
5984

6085
### Create a new AKS cluster and integrate with an existing ACR
@@ -84,6 +109,8 @@ Alternatively, you can specify the ACR name using an ACR resource ID using the f
84109
> az aks create -n myAKSCluster -g myResourceGroup --generate-ssh-keys --attach-acr /subscriptions/<subscription-id>/resourceGroups/myContainerRegistryResourceGroup/providers/Microsoft.ContainerRegistry/registries/myContainerRegistry
85110
> ```
86111
112+
This command may take several minutes to complete.
113+
87114
#### [Azure PowerShell](#tab/azure-powershell)
88115
89116
```azurepowershell
@@ -96,9 +123,42 @@ $MYACR = 'myContainerRegistry'
96123
New-AzAksCluster -Name myAKSCluster -ResourceGroupName myResourceGroup -GenerateSshKey -AcrNameToAttach $MYACR
97124
```
98125
99-
---
126+
This command may take several minutes to complete.
127+
128+
#### [Terraform](#tab/terraform)
129+
130+
```terraform
131+
# Example Usage
132+
resource "azurerm_kubernetes_cluster" "example" {
133+
name = "example-aks1"
134+
location = azurerm_resource_group.example.location
135+
resource_group_name = azurerm_resource_group.example.name
136+
dns_prefix = "exampleaks1"
137+
default_node_pool {
138+
name = "default"
139+
node_count = 1
140+
vm_size = "Standard_D2_v2"
141+
}
142+
identity {
143+
type = "SystemAssigned"
144+
}
145+
tags = {
146+
Environment = "Production"
147+
}
148+
}
149+
resource "azurerm_role_assignment" "example" {
150+
principal_id = azurerm_kubernetes_cluster.example.kubelet_identity[0].object_id
151+
role_definition_name = "AcrPull"
152+
scope = azurerm_container_registry.example.id
153+
skip_service_principal_aad_check = true
154+
}
155+
```
156+
157+
For more information about the syntax and argument reference, see [Terraform reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry).
100158

101-
This step may take several minutes to complete.
159+
This method may take several minutes to complete.
160+
161+
---
102162

103163
## Configure ACR integration for existing AKS clusters
104164

@@ -130,6 +190,20 @@ Set-AzAksCluster -Name myAKSCluster -ResourceGroupName myResourceGroup -AcrNameT
130190
> [!NOTE]
131191
> Running the `Set-AzAksCluster -AcrNameToAttach` cmdlet uses the permissions of the user running the command to create the role ACR assignment. This role is assigned to the [kubelet][kubelet] managed identity. For more information on AKS managed identities, see [Summary of managed identities][summary-msi].
132192
193+
#### [Terraform](#tab/terraform)
194+
195+
```terraform
196+
# Example Usage
197+
resource "azurerm_role_assignment" "example" {
198+
principal_id = azurerm_kubernetes_cluster.example.kubelet_identity[0].object_id
199+
role_definition_name = "AcrPull"
200+
scope = azurerm_container_registry.example.id
201+
skip_service_principal_aad_check = true
202+
}
203+
```
204+
205+
For more information about the syntax and argument reference, see [Terraform reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry).
206+
133207
---
134208

135209
### Detach an ACR from an AKS cluster

0 commit comments

Comments
 (0)