You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/aks/learn/tutorial-kubernetes-workload-identity.md
+27-76Lines changed: 27 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Tutorial - Use a workload identity with an application on Azure Kubernete
3
3
description: In this Azure Kubernetes Service (AKS) tutorial, you deploy an Azure Kubernetes Service cluster and configure an application to use a workload identity.
4
4
ms.topic: tutorial
5
5
ms.custom: devx-track-azurecli
6
-
ms.date: 01/11/2023
6
+
ms.date: 04/18/2023
7
7
---
8
8
9
9
# Tutorial: Use a workload identity with an application on Azure Kubernetes Service (AKS)
@@ -20,23 +20,19 @@ This tutorial assumes a basic understanding of Kubernetes concepts. For more inf
[!INCLUDE [preview features callout](../includes/preview/preview-callout.md)]
24
-
25
23
- This article requires version 2.40.0 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
26
24
27
-
- You have installed the latest version of the `aks-preview` extension, version 0.5.102 or later.
28
-
29
-
- The identity you are using to create your cluster has the appropriate minimum permissions. For more information on access and identity for AKS, see [Access and identity options for Azure Kubernetes Service (AKS)][aks-identity-concepts].
25
+
- The identity you're using to create your cluster has the appropriate minimum permissions. For more information on access and identity for AKS, see [Access and identity options for Azure Kubernetes Service (AKS)][aks-identity-concepts].
30
26
31
27
- If you have multiple Azure subscriptions, select the appropriate subscription ID in which the resources should be billed using the
32
28
[az account][az-account] command.
33
29
34
30
## Create a resource group
35
31
36
-
An [Azure resource group][azure-resource-group] is a logical group in which Azure resources are deployed and managed. When you create a resource group, you are prompted to specify a location. This location is:
32
+
An [Azure resource group][azure-resource-group] is a logical group in which Azure resources are deployed and managed. When you create a resource group, you're prompted to specify a location. This location is:
37
33
38
34
* The storage location of your resource group metadata.
39
-
* Where your resources will run in Azure if you don't specify another region during resource creation.
35
+
* Where your resources run in Azure if you don't specify another region during resource creation.
40
36
41
37
The following example creates a resource group named *myResourceGroup* in the *eastus* location.
42
38
@@ -61,85 +57,42 @@ The following output example resembles successful creation of the resource group
61
57
}
62
58
```
63
59
64
-
## Install the aks-preview Azure CLI extension
65
-
66
-
[!INCLUDE [preview features callout](../includes/preview/preview-callout.md)]
67
-
68
-
To install the aks-preview extension, run the following command:
69
-
70
-
```azurecli-interactive
71
-
az extension add --name aks-preview
72
-
```
73
-
74
-
Run the following command to update to the latest version of the extension released:
75
-
76
-
```azurecli-interactive
77
-
az extension update --name aks-preview
78
-
```
79
-
80
-
## Register the 'EnableWorkloadIdentityPreview' feature flag
81
-
82
-
Register the `EnableWorkloadIdentityPreview` feature flag by using the [az feature register][az-feature-register] command, as shown in the following example:
83
-
84
-
```azurecli-interactive
85
-
az feature register --namespace "Microsoft.ContainerService" --name "EnableWorkloadIdentityPreview"
86
-
```
87
-
88
-
It takes a few minutes for the status to show *Registered*. Verify the registration status by using the [az feature list][az-feature-list] command:
60
+
## Export environmental variables
89
61
90
-
```azurecli-interactive
91
-
az feature show --namespace "Microsoft.ContainerService" --name "EnableWorkloadIdentityPreview"
92
-
```
62
+
To help simplify steps to configure the identities required, the steps below define
63
+
environmental variables for reference on the cluster.
93
64
94
-
When the status shows *Registered*, refresh the registration of the *Microsoft.ContainerService* resource provider by using the [az provider register][az-provider-register] command:
65
+
Run the following commands to create these variables. Replace the default values for `RESOURCE_GROUP`, `LOCATION`, `SERVICE_ACCOUNT_NAME`, `SUBSCRIPTION`, `USER_ASSIGNED_IDENTITY_NAME`, and `FEDERATED_IDENTITY_CREDENTIAL_NAME`.
95
66
96
-
```azurecli-interactive
97
-
az provider register --namespace Microsoft.ContainerService
Create an AKS cluster using the [az aks create][az-aks-create] command with the `--enable-oidc-issuer` parameter to use the OIDC Issuer. The following example creates a cluster named *myAKSCluster* with one node in the *myResourceGroup*:
103
82
104
83
```azurecli-interactive
105
-
az aks create -g myResourceGroup -n myAKSCluster --node-count 1 --enable-oidc-issuer --enable-workload-identity --generate-ssh-keys
84
+
az aks create -g "${RESOURCE_GROUP}" -n myAKSCluster --node-count 1 --enable-oidc-issuer --enable-workload-identity
106
85
```
107
86
108
87
After a few minutes, the command completes and returns JSON-formatted information about the cluster.
109
88
110
89
> [!NOTE]
111
90
> When you create an AKS cluster, a second resource group is automatically created to store the AKS resources. For more information, see [Why are two resource groups created with AKS?][aks-two-resource-groups].
112
91
113
-
To get the OIDC Issuer URL and save it to an environmental variable, run the following command. Replace the default value for the arguments `-n`, which is the name of the cluster and `-g`, the resource group name:
92
+
To get the OIDC Issuer URL and save it to an environmental variable, run the following command. Replace the default value for the arguments `-n`, which is the name of the cluster:
114
93
115
94
```azurecli-interactive
116
-
export AKS_OIDC_ISSUER="$(az aks show -n myAKSCluster -g myResourceGroup --query "oidcIssuerProfile.issuerUrl" -otsv)"
117
-
```
118
-
119
-
## Export environmental variables
120
-
121
-
To help simplify steps to configure creating Azure Key Vault and other identities required, the steps below define
122
-
environmental variables for reference on the cluster.
123
-
124
-
Run the following commands to create these variables. Replace the default values for `RESOURCE_GROUP`, `LOCATION`, `KEYVAULT_SECRET_NAME`, `SERVICE_ACCOUNT_NAME`, `SUBSCRIPTION`, `UAID`, and `FICID`.
125
-
126
-
```bash
127
-
# environment variables for the Azure Key Vault resource
128
-
export KEYVAULT_NAME="azwi-kv-tutorial"
129
-
export KEYVAULT_SECRET_NAME="my-secret"
130
-
export RESOURCE_GROUP="resourceGroupName"
131
-
export LOCATION="westcentralus"
132
-
133
-
# environment variables for the Kubernetes Service account & federated identity credential
@@ -226,7 +179,7 @@ Serviceaccount/workload-identity-sa created
226
179
Use the [az identity federated-credential create][az-identity-federated-credential-create] command to create the federated identity credential between the managed identity, the service account issuer, and the subject.
@@ -266,7 +217,7 @@ The following output resembles successful creation of the pod:
266
217
pod/quick-start created
267
218
```
268
219
269
-
To check whether all properties are injected properly by the webhook, use
220
+
To check whether all properties are injected properly with the webhook, use
270
221
the [kubectl describe][kubelet-describe] command:
271
222
272
223
```bash
@@ -307,7 +258,7 @@ az group delete --name "${RESOURCE_GROUP}"
307
258
## Next steps
308
259
309
260
In this tutorial, you deployed a Kubernetes cluster and then deployed a simple container application to
310
-
test working with an Azure AD workload identity (preview).
261
+
test working with an Azure AD workload identity.
311
262
312
263
This tutorial is for introductory purposes. For guidance on a creating full solutions with AKS for production, see [AKS solution guidance][aks-solution-guidance].
Copy file name to clipboardExpand all lines: articles/aks/workload-identity-deploy-cluster.md
+33-19Lines changed: 33 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@
2
2
title: Deploy and configure an Azure Kubernetes Service (AKS) cluster with workload identity
3
3
description: In this Azure Kubernetes Service (AKS) article, you deploy an Azure Kubernetes Service cluster and configure it with an Azure AD workload identity.
4
4
ms.topic: article
5
+
ms.custom: devx-track-azurecli
5
6
ms.date: 04/18/2023
6
-
7
7
---
8
8
9
9
# Deploy and configure workload identity on an Azure Kubernetes Service (AKS) cluster
@@ -23,55 +23,69 @@ This article assumes you have a basic understanding of Kubernetes concepts. For
23
23
24
24
- If you have multiple Azure subscriptions, select the appropriate subscription ID in which the resources should be billed using the [az account][az-account] command.
25
25
26
+
## Export environmental variables
27
+
28
+
To help simplify steps to configure the identities required, the steps below define
29
+
environmental variables for reference on the cluster.
30
+
31
+
Run the following commands to create these variables. Replace the default values for `RESOURCE_GROUP`, `LOCATION`, `SERVICE_ACCOUNT_NAME`, `SUBSCRIPTION`, `USER_ASSIGNED_IDENTITY_NAME`, and `FEDERATED_IDENTITY_CREDENTIAL_NAME`.
Create an AKS cluster using the [az aks create][az-aks-create] command with the `--enable-oidc-issuer` parameter to use the OIDC Issuer. The following example creates a cluster named *myAKSCluster* with one node in the *myResourceGroup*:
29
46
30
47
```azurecli-interactive
31
-
az group create --name myResourceGroup --location eastus
48
+
az group create --name "${RESOURCE_GROUP}" --location "${LOCATION}"
32
49
33
-
az aks create -g myResourceGroup -n myAKSCluster --enable-oidc-issuer --enable-workload-identity
50
+
az aks create -g "${RESOURCE_GROUP}" -n myAKSCluster --enable-oidc-issuer --enable-workload-identity
34
51
```
35
52
36
53
After a few minutes, the command completes and returns JSON-formatted information about the cluster.
37
54
38
55
> [!NOTE]
39
56
> When you create an AKS cluster, a second resource group is automatically created to store the AKS resources. For more information, see [Why are two resource groups created with AKS?][aks-two-resource-groups].
40
57
41
-
To get the OIDC Issuer URL and save it to an environmental variable, run the following command. Replace the default values for the cluster name and the resource group name.
58
+
To get the OIDC Issuer URL and save it to an environmental variable, run the following command. Replace the default value for the arguments `-n`, which is the name of the cluster:
42
59
43
60
```bash
44
-
export AKS_OIDC_ISSUER="$(az aks show -n myAKSCluster -g myResourceGroup --query "oidcIssuerProfile.issuerUrl" -otsv)"
61
+
export AKS_OIDC_ISSUER="$(az aks show -n myAKSCluster -g "${RESOURCE_GROUP}" --query "oidcIssuerProfile.issuerUrl" -otsv)"
45
62
```
46
63
47
64
## Create a managed identity
48
65
49
66
Use the Azure CLI [az account set][az-account-set] command to set a specific subscription to be the current active subscription. Then use the [az identity create][az-identity-create] command to create a managed identity.
50
67
51
68
```azurecli
52
-
export SUBSCRIPTION_ID="$(az account show --query id --output tsv)"
Create a Kubernetes service account and annotate it with the client ID of the managed identity created in the previous step. Use the [az aks get-credentials][az-aks-get-credentials] command and replace the values for the cluster name and the resource group name.
63
81
64
82
```azurecli
65
-
az aks get-credentials -n myAKSCluster -g myResourceGroup
83
+
az aks get-credentials -n myAKSCluster -g "${RESOURCE_GROUP}"
66
84
```
67
85
68
-
Copy and paste the following multi-line input in the Azure CLI, and update the values for `SERVICE_ACCOUNT_NAME` and `SERVICE_ACCOUNT_NAMESPACE` with the Kubernetes service account name and its namespace.
86
+
Copy and paste the following multi-line input in the Azure CLI.
@@ -94,7 +108,7 @@ Serviceaccount/workload-identity-sa created
94
108
Use the [az identity federated-credential create][az-identity-federated-credential-create] command to create the federated identity credential between the managed identity, the service account issuer, and the subject.
0 commit comments