Kubernetes Labs · Lab 8 of 9

Azure AKS: App Routing, ACR and Microsoft Entra Workload ID

Create an AKS cluster with the free control-plane tier, import an image into Azure Container Registry, expose the app with the application routing add-on (managed NGINX), and give pods an Azure identity with no secrets.

Environment
Azure
Level
Intermediate
Time
About 50 min
Cost
≈ $0.15 per hour; delete the resource group after

You will build

A two-node AKS cluster pulling from your own registry, serving the app on a public IP through app routing, with pods authenticated to Azure through a federated managed identity.

Before you start

Members can save this page, take notes and track progress. See membership · Sign in

On AKS, Azure runs the control plane (free on the Free tier, with an SLA on the Standard tier) and your nodes run as a VM scale set in a virtual network. Azure creates a second resource group, MC_shop-rg_shop-aks_…, for the cluster's own resources (VMs, disks, load balancer); don't edit it by hand.

UsersHTTP(S)Resource group shop-rgAzure Load Balancerpublic IP for app routingAKS control planemanaged by Azure, OIDC issuerAKS node pool (VM scale set) in a VNet subnetApp routing (managed NGINX)IngressClass webapprouting…Pods web × 2service account shop/webkubelet identityAcrPull on the registryWorkload ID webhookadds token settings to podsAzure Container Registryattached with --attach-acrManaged identityfederated credential, Key Vault…
AKS: Azure runs the control plane, app routing serves the Ingress, identities replace secrets

The components

  • Resource group shop-rg: holds everything you create, so one delete removes it all.
  • AKS control plane: managed by Azure; it also runs an OIDC issuer that signs service account tokens.
  • Node pool: a VM scale set running kubelet and containerd.
  • Azure Container Registry (ACR): --attach-acr gives the nodes' kubelet identity the AcrPull role, so pulls need no secrets.
  • Application routing add-on: a managed NGINX ingress controller behind an Azure Load Balancer with a public IP. It serves Ingress objects with class webapprouting.kubernetes.azure.com.
  • Microsoft Entra Workload ID: a webhook adds token settings to pods that opt in, and Entra ID trusts tokens from the cluster's issuer for one exact service account.
PodSA token signed by AKSMicrosoft Entra IDchecks federated credentialAzure APIKey Vault, Storage…AKS OIDC issuerpublishes signing keys1. SA token2. verify signature3. Azure tokensubject system:serviceaccount:shop:web must match the federated credentialThe pod uses the managed identity without any client secret
Microsoft Entra Workload ID on AKS

Cost: the Free tier control plane costs nothing; two Standard_B2s nodes, the load balancer, public IP and a Basic registry come to roughly $0.15 per hour. Delete the resource group when you finish.

About the outputs: the manifests in this lab were validated against a real Kubernetes 1.37 API server (kubectl apply --dry-run=server), and the dry-run output shown is real. The cloud commands were not run for you: they need your own account, and their output contains account IDs, names and addresses that differ for everyone. Those steps tell you what to check instead.

Project structure

aks/
└── app.yaml   # namespace, service account (workload identity), Deployment, Service, Ingress

Download starter filesDownload finished project

Steps

  1. 1Sign in and create a resource group

    Run
    az login
    az account set --subscription SUBSCRIPTION_ID
    az group create --name shop-rg --location westeurope
    
    Check:

    az group create prints JSON with "provisioningState": "Succeeded".

  2. 2Create a registry and import the image

    az acr import copies the image from Docker Hub into your registry inside Azure; nothing goes through your computer.

    Run
    ACR=shopacr$RANDOM
    az acr create --resource-group shop-rg --name $ACR --sku Basic
    az acr import --name $ACR --source docker.io/traefik/whoami:v1.11.0 --image whoami:v1.11.0
    az acr repository list --name $ACR --output table
    
    Check:

    The repository list shows whoami. Note the registry name: the next steps use $ACR.

  3. 3Create the cluster

    Takes 5–10 minutes. The flags turn on the OIDC issuer and Workload ID, the app routing add-on, and pull access to your registry.

    Run
    az aks create --resource-group shop-rg --name shop-aks --tier free \
      --node-count 2 --node-vm-size Standard_B2s \
      --enable-oidc-issuer --enable-workload-identity --enable-app-routing \
      --attach-acr $ACR --generate-ssh-keys
    az aks get-credentials --resource-group shop-rg --name shop-aks
    kubectl get nodes
    kubectl get ingressclass
    
    Check:

    Two Ready nodes named aks-nodepool1-…, and an IngressClass webapprouting.kubernetes.azure.com.

    Hint

    Standard_B2s may be unavailable in some regions or subscriptions; pick another small size from az vm list-sizes --location westeurope.

  4. 4Create a managed identity and trust the service account

    The federated credential tells Entra ID: tokens issued by this cluster for system:serviceaccount:shop:web may act as this managed identity. Grant the identity whatever Azure roles the app needs (Key Vault secrets, Storage) on those resources only.

    Run
    az identity create --resource-group shop-rg --name shop-web-id
    ISSUER=$(az aks show --resource-group shop-rg --name shop-aks --query oidcIssuerProfile.issuerUrl --output tsv)
    az identity federated-credential create --name shop-web --identity-name shop-web-id --resource-group shop-rg \
      --issuer $ISSUER --subject system:serviceaccount:shop:web --audience api://AzureADTokenExchange
    CLIENT_ID=$(az identity show --resource-group shop-rg --name shop-web-id --query clientId --output tsv)
    
    Check:

    az identity federated-credential list --identity-name shop-web-id --resource-group shop-rg shows the subject system:serviceaccount:shop:web.

  5. 5The app

    The service account carries the identity's client ID; the pod label azure.workload.identity/use: "true" asks the webhook to inject the token. The Ingress uses the app routing class.

    app.yaml
    apiVersion: v1
    kind: Namespace
    metadata:
      name: shop
    ---
    # Microsoft Entra Workload ID: tokens for this service account are exchanged for the managed identity's.
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: web
      namespace: shop
      annotations:
        azure.workload.identity/client-id: MANAGED_IDENTITY_CLIENT_ID
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: web
      namespace: shop
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: web
      template:
        metadata:
          labels:
            app: web
            azure.workload.identity/use: "true"
        spec:
          serviceAccountName: web
          containers:
            - name: whoami
              image: SHOPACR.azurecr.io/whoami:v1.11.0
              ports:
                - name: http
                  containerPort: 80
              readinessProbe:
                httpGet:
                  path: /health
                  port: http
              resources:
                requests:
                  cpu: 50m
                  memory: 32Mi
                limits:
                  memory: 64Mi
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: web
      namespace: shop
    spec:
      selector:
        app: web
      ports:
        - name: http
          port: 80
          targetPort: http
    ---
    # The application routing add-on (managed NGINX) serves this Ingress on a public Azure Load Balancer IP.
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: web
      namespace: shop
    spec:
      ingressClassName: webapprouting.kubernetes.azure.com
      rules:
        - http:
            paths:
              - path: /
                pathType: Prefix
                backend:
                  service:
                    name: web
                    port:
                      name: http
    
  6. 6Fill in the placeholders and validate

    Run
    sed -i "s/SHOPACR/$ACR/; s/MANAGED_IDENTITY_CLIENT_ID/$CLIENT_ID/" app.yaml
    kubectl apply --dry-run=client -f app.yaml
    

    Expected output

    namespace/shop created (dry run)
    serviceaccount/web created (dry run)
    deployment.apps/web created (dry run)
    service/web created (dry run)
    ingress.networking.k8s.io/web created (dry run)
    Hint

    On macOS use sed -i '' instead of sed -i.

  7. 7Apply, then call the app

    Run
    kubectl apply -f app.yaml
    kubectl -n shop get ingress web --watch      # wait for ADDRESS, then Ctrl+C
    IP=$(kubectl -n shop get ingress web -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    for i in 1 2 3 4; do curl -s http://$IP/ | grep Hostname; done
    
    Check:

    ADDRESS shows a public IP within a minute or two, and both pod names appear.

  8. 8Confirm the identity was injected

    Run
    kubectl -n shop get pod -l app=web -o jsonpath='{.items[0].spec.containers[0].env[*].name}{"\n"}'
    
    Check:

    The list includes AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_FEDERATED_TOKEN_FILE and AZURE_AUTHORITY_HOST. Azure SDKs read these automatically.

Clean up

One command removes the cluster, its MC_… resource group, the registry, the identity and the public IP:

az group delete --name shop-rg --yes --no-wait

A few minutes later, az group list --query "[?starts_with(name, 'shop-rg') || starts_with(name, 'MC_shop-rg')].name" should print an empty list.

In production

The add-ons used here are production-grade; what changes is how the cluster is built, connected and governed.

What changes

In this lab In production
az aks create from a laptop Terraform (azurerm) or Bicep in a pipeline, one state per environment
Free tier control plane Standard tier (uptime SLA) for production clusters
Default networking, public API server Your own VNet and subnets (Azure CNI), private cluster or API server authorized IP ranges
One node pool A system pool for add-ons and user pools for apps, across availability zones, with the cluster autoscaler
HTTP through app routing HTTPS with certificates from Key Vault (app routing integrates with it), and Azure Front Door or a WAF in front
Local accounts and admin kubeconfig Microsoft Entra ID integration with Kubernetes RBAC or Azure RBAC; local accounts disabled

Production checklist

  • Cluster, networks, identities and role assignments defined in Terraform or Bicep
  • Standard tier, availability zones, separate system and user node pools
  • Entra ID authentication for people; local accounts disabled
  • Workload ID for every pod that calls Azure; no client secrets in Kubernetes
  • Images only from ACR, scanned with Microsoft Defender for Containers
  • HTTPS with Key Vault certificates; WAF in front of public apps
  • Container insights or managed Prometheus/Grafana, with alerts; planned upgrades with the auto-upgrade channel

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake