AKS and Microsoft Entra ID

Demo source and Kubernetes manifest

The homepage is public. A visitor selects Sign in with Microsoft Entra ID to open the protected account page. The account page displays the name, sign-in name, identity provider, user object ID and tenant ID when Entra supplies them. The app keeps raw tokens out of the page and uses an HTTP-only session cookie.

The AKS kubelet identity pulls the private application image from Azure Container Registry. The visitor signs in through a separate, single-tenant Entra app registration. Caddy terminates HTTPS on the public AKS Service and proxies to the Node app on port 8080.

Select a screenshot to open the original-sized crop. Sensitive values are covered in the published copies.

1. Create the AKS cluster in the Azure portal

Open Kubernetes services > Create > Kubernetes cluster. Choose the subscription and create a dedicated resource group. In Basics, select Dev/Test, choose the region, name the cluster and verify Free pricing tier.

Create a dedicated resource group from the AKS wizard

AKS Basics shows Dev/Test, UK South and Free tier

In Node pools, edit the system pool. Select a supported Linux VM with at least four vCPUs. The rehearsal used two fixed Standard_D4as_v5 nodes and no extra node pool. Select Manual and set Node count to 2.

Azure VM picker shows the four-vCPU D4as v5 size

The system pool editor shows the VM size and a fixed count of two

Review networking. The AKS cluster uses the Standard Azure Load Balancer. The application manifest adds a public listener with an Azure DNS label. In Integrations, select an existing private ACR in your tenant if you have one. This walkthrough reused the Container Apps demo’s Basic registry and created a separate image repository in it.

AKS networking settings in the Azure portal

AKS Integrations shows the existing Azure Container Registry selected

In Monitoring, leave optional Container Logs, Prometheus and Grafana disabled for this rehearsal. Review the configuration and select Create.

Monitoring settings with the optional services disabled

The AKS review page summarizes the Free-tier cluster configuration

The Azure portal reports the AKS deployment is in progress

2. Register the website in Microsoft Entra

  1. Pick a unique DNS label. Use the public name <dns-label>.<azure-region>.cloudapp.azure.com in this walkthrough. Under App registrations > New registration, choose Single tenant only and add a Web redirect URI at https://<hostname>/auth/redirect.
  2. After registration, also add https://<hostname>/ as a Web redirect URI so Entra can return to the public homepage after sign-out.
  3. From the app registration overview, open the link under Managed application in local directory. Under Properties, set Assignment required? to Yes and save. Under Users and groups > Add user/group, select the presenter and choose Assign.
  4. Under Certificates & secrets, create an expiring secret for the confidential web client. Use it to provision the Kubernetes Secret. Keep the value out of screenshots, manifests and Git.

The registration form shows a single tenant and a Web callback URI

Enterprise application Properties shows Assignment required set to Yes

The Add Assignment interface shows one selected user and Default Access

The registered presenter appears in Users and groups

3. Build and deploy the application

Connect to the cluster through Overview > Connect. Use the available Kubernetes authentication mode and a principal permitted to create workloads and Secrets in the demo namespace. The portal shows cluster settings and workload status. Use Cloud Shell or a signed-in local terminal to build the image, create the Secret and apply the manifest. The rehearsal used the local terminal for these commands.

AKS Overview shows the cluster running with a succeeded operation status

git clone https://github.com/kramit/aks-entra-auth-demo.git
cd aks-entra-auth-demo
export ACR='<registry-name>'
export RG='<aks-resource-group>'
export AKS='<cluster-name>'
export DNS_LABEL='<dns-label>'
export REGION='<azure-region-name>'
export HOSTNAME_PUBLIC="$DNS_LABEL.$REGION.cloudapp.azure.com"

tag=$(git rev-parse --short=12 HEAD)
az acr build -r "$ACR" -t "aks-entra-demo:$tag" .
digest=$(az acr repository show -n "$ACR" --image "aks-entra-demo:$tag" --query digest -o tsv)
registry=$(az acr show -n "$ACR" --query loginServer -o tsv)
image="$registry/aks-entra-demo@$digest"
az aks get-credentials -g "$RG" -n "$AKS"
kubectl create namespace entra-demo

Create an Opaque Secret called entra-demo-settings in entra-demo. Supply TENANT_ID, CLIENT_ID, CLIENT_SECRET, SESSION_SECRET (a cryptographically random value), and PUBLIC_URL (https://<hostname>/). For a Cloud Shell rehearsal, read the credential without terminal echo and pipe the Secret directly to Kubernetes.

read -rp 'Tenant ID: ' tenant_id
read -rp 'Application (client) ID: ' client_id
read -rsp 'Client secret: ' client_secret
printf '\n'
session_secret=$(openssl rand -base64 48)

{
  printf 'TENANT_ID=%s\nCLIENT_ID=%s\n' "$tenant_id" "$client_id"
  printf 'CLIENT_SECRET=%s\nSESSION_SECRET=%s\n' "$client_secret" "$session_secret"
  printf 'PUBLIC_URL=https://%s/\n' "$HOSTNAME_PUBLIC"
} | kubectl -n entra-demo create secret generic entra-demo-settings --from-env-file=/dev/stdin
unset client_secret session_secret

sed -e "s|DEMO_DNS_LABEL|$DNS_LABEL|g" \
    -e "s|DEMO_HOSTNAME|$HOSTNAME_PUBLIC|g" \
    -e "s|DEMO_IMAGE_REFERENCE|$image|g" kubernetes.yaml |
  kubectl -n entra-demo apply -f -
kubectl -n entra-demo rollout status deploy/entra-demo
kubectl -n entra-demo get pods,svc

In the portal, open Workloads > Deployments and confirm 1/1 Ready. Open Services, gateways and ingresses > Services and confirm the web Service is a healthy LoadBalancer with ports 80 and 443.

The AKS Workloads page shows the demo deployment at 1/1 ready

The Deployment overview shows the namespace, selector and ready replica

The AKS Services page shows the healthy web LoadBalancer Service and its two public ports

The public IP and its DNS record can take several minutes to appear. Caddy then requests a public certificate. The manifest uses an in-memory session store for the single demo replica, and pod-local certificate storage. Replicas or frequent replacements need shared session and certificate storage. If the image fails to pull, check the kubelet’s registry access. If HTTPS is pending, check that the hostname resolves to the Service public IP and inspect the https container’s logs.

4. Rehearse the sign-in flow

  1. Open https://<hostname>/ in Edge InPrivate. Show that Public landing page opens before sign-in. The public landing page shows the Sign in with Microsoft Entra ID button

  2. Select Sign in with Microsoft Entra ID. Sign in as the assigned presenter. Complete any tenant-approved consent and MFA prompts.

    Microsoft Entra shows a first-run permissions prompt

  3. Show Signed-in user. The server has exchanged the authorization code and created a session. The page renders selected Entra claims.

    The account page displays selected identity claims and a Sign out button, with personal values covered

  4. Select Sign out. Complete the Entra account picker if shown. Confirm that the homepage is public again and that opening /account starts a new sign-in.

    Microsoft prompts for the account to sign out of

    Edge is back on the public landing page after sign-out

    Opening the account page again sends Edge to the Microsoft account picker

The rehearsal verified the full browser sequence in Edge InPrivate, including the return to the public homepage and the new Entra sign-in for the protected route.

Costs and repeat runs

The Free tier covers the control plane. The node VMs, disks, Azure Load Balancer, public IPs, registry usage and subscription-level services can still incur charges. Use Stop on the AKS Overview page between classes to stop worker VM compute. Select Start before class and wait for the deployment and HTTPS endpoint to recover. Review residual costs in Cost Management. Remove the dedicated resource group and its Entra registration when finished. A shared ACR stays with its original resource group.

Create AKS in the Azure portal · AKS system pool requirements · AKS and ACR · AKS public load balancer and DNS label