Skip to content

Commit 8151cd9

Browse files
Merge pull request #234227 from MGoedtel/bug84630
Updated WI Deploy code sample
2 parents 54d96dc + 35239ab commit 8151cd9

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

articles/aks/workload-identity-deploy-cluster.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Deploy and configure an Azure Kubernetes Service (AKS) cluster with workl
33
description: In this Azure Kubernetes Service (AKS) article, you deploy an Azure Kubernetes Service cluster and configure it with an Azure AD workload identity (preview).
44
ms.topic: article
55
ms.custom: devx-track-azurecli
6-
ms.date: 03/14/2023
6+
ms.date: 04/12/2023
77
---
88

99
# Deploy and configure workload identity (preview) on an Azure Kubernetes Service (AKS) cluster
@@ -19,7 +19,7 @@ This article assumes you have a basic understanding of Kubernetes concepts. For
1919

2020
- This article requires version 2.40.0 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
2121

22-
- The identity you're using to create your cluster has the appropriate minimum permissions. For more details on access and identity for AKS, see [Access and identity options for Azure Kubernetes Service (AKS)][aks-identity-concepts].
22+
- The identity you're using to create your cluster has the appropriate minimum permissions. For more information about access and identity for AKS, see [Access and identity options for Azure Kubernetes Service (AKS)][aks-identity-concepts].
2323

2424
- 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.
2525

@@ -106,15 +106,14 @@ Copy and paste the following multi-line input in the Azure CLI, and update the v
106106
```bash
107107
export SERVICE_ACCOUNT_NAME="workload-identity-sa"
108108
export SERVICE_ACCOUNT_NAMESPACE="my-namespace"
109+
export USER_ASSIGNED_CLIENT_ID="$(az identity show --resource-group "${RESOURCE_GROUP}" --name "${UAID}" --query 'clientId' -otsv)"
109110

110111
cat <<EOF | kubectl apply -f -
111112
apiVersion: v1
112113
kind: ServiceAccount
113114
metadata:
114115
annotations:
115116
azure.workload.identity/client-id: "${USER_ASSIGNED_CLIENT_ID}"
116-
labels:
117-
azure.workload.identity/use: "true"
118117
name: "${SERVICE_ACCOUNT_NAME}"
119118
namespace: "${SERVICE_ACCOUNT_NAMESPACE}"
120119
EOF
@@ -139,13 +138,41 @@ az identity federated-credential create --name myfederatedIdentity --identity-na
139138
140139
## Deploy your application
141140

141+
When you deploy your application pods, the manifest should reference the service account created in the **Create Kubernetes service account** step. The following manifest shows how to reference the account, specifically *metadata\namespace* and *spec\serviceAccountName* properties:
142+
143+
```yml
144+
cat <<EOF | kubectl apply -f -
145+
apiVersion: v1
146+
kind: Pod
147+
metadata:
148+
name: quick-start
149+
namespace: SERVICE_ACCOUNT_NAMESPACE
150+
labels:
151+
azure.workload.identity/use: "true"
152+
spec:
153+
serviceAccountName: workload-identity-sa
154+
EOF
155+
```
156+
142157
> [!IMPORTANT]
143158
> Ensure your application pods using workload identity have added the following label [azure.workload.identity/use: "true"] to your running pods/deployments, otherwise the pods will fail once restarted.
144159
145160
```azurecli-interactive
146161
kubectl apply -f <your application>
147162
```
148163

164+
To check whether all properties are injected properly by the webhook, use the [kubectl describe][kubectl-describe] command:
165+
166+
```bash
167+
kubectl describe pod containerName
168+
```
169+
170+
To verify that pod is able to get a token and access the resource, use the kubectl logs command:
171+
172+
```bash
173+
kubectl logs containerName
174+
```
175+
149176
## Optional - Grant permissions to access Azure Key Vault
150177

151178
This step is necessary if you need to access secrets, keys, and certificates that are mounted in Azure Key Vault from a pod. Perform the following steps to configure access with a managed identity. These steps assume you have an Azure Key Vault already created and configured in your subscription. If you don't have one, see [Create an Azure Key Vault using the Azure CLI][create-key-vault-azure-cli].
@@ -181,6 +208,7 @@ az aks update --resource-group myResourceGroup --name myAKSCluster --enable-work
181208
In this article, you deployed a Kubernetes cluster and configured it to use a workload identity in preparation for application workloads to authenticate with that credential. Now you're ready to deploy your application and configure it to use the workload identity with the latest version of the [Azure Identity][azure-identity-libraries] client library. If you can't rewrite your application to use the latest client library version, you can [set up your application pod][workload-identity-migration] to authenticate using managed identity with workload identity as a short-term migration solution.
182209

183210
<!-- EXTERNAL LINKS -->
211+
[kubectl-describe]: https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#describe
184212

185213
<!-- INTERNAL LINKS -->
186214
[kubernetes-concepts]: concepts-clusters-workloads.md

0 commit comments

Comments
 (0)