Back to Terraform

AKS and ACR: Cluster Provisioning, Workload Identity and Application Ownership

November 6, 2026 Wasil Zafar 20 min read

Separate Azure cluster infrastructure from Kubernetes API resources and image promotion

Table of Contents

  1. Choose AKS Network, Identity and Node-Pool Contracts
  2. Keep Registry Ownership Separate from Image Builds
  3. Distinguish Cluster, Kubelet and Workload Identities
  4. Stage Kubernetes Provider Operations After API Readiness
  5. Verify One Workload and Respect Teardown Order

Choose AKS Network, Identity and Node-Pool Contracts

Three contracts are settled before the first apply. Pod addressing, API-server exposure and node-pool shape are create-time properties of an AKS cluster. Change your mind later and the honest answer is a second cluster, not an in-place edit of the first.

Pick the pod addressing model first. Azure CNI gives every pod an address from the VNet, so pods are routable from the network root without NAT. Overlay is the same plugin with network_plugin_mode set to overlay, and it draws pod addresses from a separate CIDR, which is usually what a shared VNet with a fixed address plan wants.

Subnet size follows pods, not nodes. With VNet-allocated pods, each node reserves addresses up to its maximum pod count, and the reservation happens before those pods exist. Size the subnet from pods per node times node count, then leave room for the surge capacity an upgrade needs.

Private or public is an operating choice. A private cluster puts the API server behind a private endpoint and a private DNS zone, so only a runner inside the VNet or a connected network can plan against it. Authorized IP ranges on a public endpoint are easier to operate and still closed to the open internet.

The cluster identity needs network rights up front. On a bring-your-own subnet, AKS creates the internal load balancer and its rules there, so the control-plane identity needs Network Contributor on that subnet. Discovering this when the first Service is created is a late and confusing failure.

Node pools are long-lived contracts. The system pool carries CoreDNS and the CNI, so it should be tainted against application pods and spread across zones. User pools then carry their own taints, autoscaling bounds and a max_pods value that matches the address budget.

Tier buys support, not capability. The free tier carries no financially backed uptime SLA, the standard tier adds one, and the premium tier targets mission-critical and long-term-support cases. Choose the tier from the cost of an outage rather than from habit.

Name the upgrade owner in the contract. An automatic channel plus a maintenance window is a decision someone must own; without an owner the cluster drifts until an add-on and a node image disagree.

Choose AKS Network, Identity and Node-Pool Contracts
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    NET["VNet and pod subnet
from the network root"] --> CNI{"Does a pod need
a VNet address?"} CNI -->|"yes, flat routing"| AZ["Azure CNI
subnet sized per pod"] CNI -->|"no"| OV["Overlay CNI
separate pod CIDR"] AZ --> REACH{"Can the runner
reach the API?"} OV --> REACH REACH -->|"private"| PRIV["Private cluster
private DNS zone"] REACH -->|"public"| PUB["Authorized ranges
runner egress listed"] PRIV --> POOL["System pool zoned and tainted
user pools bounded"] PUB --> POOL POOL --> OWN{"Who owns
upgrades?"} OWN -->|"named platform team"| OK["Channel plus window
add-ons upgraded in order"] OWN -->|"nobody"| DRIFT["Version skew
plane, nodes, add-ons"] DRIFT -.->|"first symptom"| BAD["CRD or add-on fails
after a node image move"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class NET,POOL primary; class AZ,OV,PRIV,PUB secondary; class OK ok; class CNI,REACH,OWN warn; class DRIFT,BAD danger;
Three contracts and three ownership roots around one AKS cluster The network root owns the VNet, pod subnet, private DNS zones and the address budget. The cluster root owns the API server, a tainted system pool and bounded user pools, plus the create-time CNI and endpoint choices. The application root owns only the namespace, the service account, the deployment and the workload identity annotation. Connectors show that the network root supplies subnets and name resolution, and the cluster root supplies the API endpoint to the application root. Three contracts, three ownership roots Pod addressing, API exposure and node-pool shape are create-time decisions. 1 Network root addresses and name resolution VNet and pod subnet NSG, routes, delegation Private DNS zones registry and API names Subnet rights Network Contributor Address budget pods before nodes 2 Cluster root one state, Azure API only API server private endpoint or ranges System node pool CoreDNS, zones, taint User node pools bounds, taints, max pods Frozen at create CNI mode, endpoint 3 Application root Kubernetes objects only Namespace one team, one quota Service account the federation subject Deployment and Service image digest, no secret Workload identity annotated, not stored The network root owns addresses, the cluster root owns the API, the application root owns objects Replace a create-time contract and you rebuild the cluster; the other two roots only need new outputs.

Keep Registry Ownership Separate from Image Builds

The registry outlives every cluster. Images are pushed many times a day, while a cluster changes on a different schedule and may be rebuilt without losing a single artifact. Give the registry its own root and its own state file.

Builds belong to CI, not to the cluster root. A build identity with push rights on one registry produces the artifact; nothing in the cluster needs to know how it was produced. A server-side build also keeps a Docker daemon off the runner.

A tag is a label; a digest is the release. Tags are mutable by design, so two builds can share one name and a rollback can silently land on different bytes. Promote the digest and let the tag live in release notes and dashboards.

Immutability is enforced at promotion. Untagged-manifest retention and soft delete solve cleanup and recovery, not overwriting. The promotion job should refuse to republish an existing release tag and record the digest it approved.

Pull permission is one role assignment. Grant AcrPull to the kubelet identity and scope it to the registry rather than the subscription. Skip the admin account entirely: a registry password in a Secret is a credential that never rotates.

Premium is a network decision. Private link, a firewall with a deny default and geo-replication only exist above the lower tiers. On a private-endpoint design the cluster resolves the registry name through the private DNS zone, so registry and network roots must agree on that zone.

Replication does not move ownership. A geo-replica serves pulls closer to the cluster and survives a regional failure, while the repository, policy and lifecycle stay in one place. Treat replicas as copies of one registry, not as a second registry to administer. Terraform 1.17.1 with hashicorp/azurerm 5.13.0 is the pair this article was checked against; pin both rather than floating a range.

Keep Registry Ownership Separate from Image Builds
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    COMMIT["Commit and lockfile"] --> BUILD["CI build
push with build identity"] BUILD --> TAG{"Release tag
already published?"} TAG -->|"yes"| REJECT["Promotion refused
published digest unchanged"] TAG -->|"no"| DIGEST["Digest recorded
sha256 of the image"] DIGEST --> SCAN{"Scan result
at promotion?"} SCAN -->|"critical"| QUAR["Digest quarantined
not deployed"] SCAN -->|"clean"| DEPLOY["Deployment names
image by digest"] DEPLOY --> PULL{"Kubelet identity
has AcrPull?"} PULL -->|"no"| DENY["ImagePullBackOff
no application log"] PULL -->|"yes"| DNS{"Registry name resolves
to the private endpoint?"} DNS -->|"no"| TIMEOUT["Pull timeout
name resolves to public edge"] DNS -->|"yes"| RUN["Pod starts
no registry secret"] RUN -.->|"retention removed
an older digest"| ROLL["Rollback cannot pull"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class COMMIT,DIGEST primary; class BUILD,DEPLOY secondary; class RUN ok; class TAG,SCAN,PULL,DNS warn; class REJECT,QUAR,DENY,TIMEOUT,ROLL danger;

Distinguish Cluster, Kubelet and Workload Identities

Three actors, three credentials, three blast radii. The control plane, the node agent and the application each authenticate to Azure separately. Most AKS permission incidents begin with treating them as one identity.

The cluster identity is ARM plumbing. AKS uses it to create the node resource group, load balancers, public IPs and disks. On a bring-your-own network it also needs rights on the subnet, and it needs nothing that resembles application data access.

The kubelet identity is node-wide. Every pod scheduled on a node can reach what that node identity can reach through the instance metadata endpoint. Restrict the kubelet_identity to registry pulls and disk attachment, and assume an unblocked pod can use all of it.

Workload identity is per service account. The cluster issues OIDC tokens, a federated credential trusts one subject, and the pod exchanges its projected token for an Entra token. No client secret is stored, and two teams in one cluster never share a credential.

The federation is a triple. Issuer, subject and audience must all match: the subject names the namespace and the service account, and a typo there fails the exchange with a message that rarely mentions the subject. The audience is the token exchange scope, not your API.

Grant on the target, not on the identity. A federated credential proves who the pod is; a role assignment decides what it may touch. Scope that assignment to the Key Vault, storage account or secret the workload actually reads.

One mechanism per cluster. Mixing the older pod-managed identity path with workload identity leaves two credential routes to debug and two ways to leak a token. Pick federation and remove the alternative.

Switch the issuer on at creation. Both oidc_issuer_enabled and workload_identity_enabled are cluster settings, and disabling them later invalidates every federated credential that trusts that issuer.

Cluster, kubelet and workload identities have different scopes Three lanes separate the actors. The cluster identity belongs to the AKS control plane and reaches the node resource group, load balancers and subnet rules. The kubelet identity belongs to the node agent and reaches the registry for pulls and the disk service for attachments. The workload identity belongs to one Kubernetes service account, trusted through a federated credential, and reaches a single Azure resource through one role assignment. Three actors, three credentials, three blast radii Workload identity exists so application permissions never sit on the node. Cluster identity control plane only AKS control plane the managed API process cluster identity system or user assigned subnet and node RG load balancers, disks Kubelet identity every node, every pod kubelet process runs on every node kubelet identity created by AKS or supplied registry and disks never application data Workload identity one service account service account namespace-scoped subject federated credential issuer, subject, audience managed identity one role on one target The node identity is reachable from every pod on that node Through the instance metadata endpoint, an unblocked pod inherits the kubelet identity. Keep application grants off it.

Stage Kubernetes Provider Operations After API Readiness

The Kubernetes provider is a client, and clients connect at plan time. It is not a resource in the graph, so no dependency edge makes it wait for a cluster. If the API server is unreachable when the plan starts, the run ends before a diff exists.

Split infrastructure from workload. One root owns the VNet attachment, cluster, node pools, add-ons and identity plumbing. A second root owns the provider configuration, the namespace, service accounts, workloads and services, and reads the endpoint from published outputs.

Keep credentials short-lived. Static cluster credentials sit in state, and the token-based ones expire in the middle of a long apply, which is exactly the wrong combination for a pipeline. An exec credential that fetches a token when it is used is the durable choice, and it leaves nothing sensitive behind.

Reachability is a design input, not an error message. A private endpoint means the runner runs inside the VNet or a connected network; a public endpoint with authorized ranges means the runner's egress address is on the list. A laptop plan fails at provider configuration before it can show you anything useful.

Readiness has three gates. The cluster must report a succeeded provisioning state, the API must answer its readiness endpoint, and the nodes plus system add-ons must be ready before a manifest is planned. A custom resource installed by an add-on needs its CRD to exist first.

Put the gate in the pipeline, between the two roots. Apply infrastructure, publish outputs, probe readiness, then plan the workload root. Terraform orders resources inside a state, not across a hand-off between two runs.

Give the deploy identity only namespace rights. The workload pipeline needs to create and update the objects it owns, not to administer nodes or policy. Cluster-admin in a pipeline is a permanent grant for a temporary job.

One root fails at provider configuration while two roots pass through a readiness gate The left panel shows a single root where Terraform plans the Kubernetes provider and the cluster in the same state, so the provider tries to connect to an endpoint that does not exist and the run aborts. The right panel shows the infrastructure root applied first, its host, certificate and issuer outputs published, a readiness gate that probes the API and nodes, and only then the workload root planned and applied. The plan fails before the graph, so stage the hand-off Provider configuration runs during plan and cannot depend on a cluster the same run creates. One root provider and cluster in the same state terraform plan provider starts, reads kube config API server unreachable the endpoint does not exist yet run aborts no diff, no useful error depends_on cannot help the client is not a graph node Two roots a pipeline step between them apply infrastructure root publishes host, CA and issuer readiness gate readiness endpoint, nodes Ready apply workload root namespace, account, deployment objects reconciled one digest, one identity The hand-off is a pipeline step, not a Terraform dependency Apply, publish, probe, then plan. Anything else plans against an API that is not there yet.

Verify One Workload and Respect Teardown Order

Verify one workload, not a platform. One namespace, one deployment, one service and one identity prove registry pull, scheduling, token exchange and log delivery. Ingress, autoscaling and a service mesh come after the straight line works.

Break the two paths separately. Remove the registry permission to prove the pull path, then remove a role assignment to prove the identity path. A single test that fails tells you nothing about which boundary broke.

Teardown follows the graph you created. Workload objects go first, then the node pools, the cluster, the registry and finally the network pieces. Reversing that order strands cloud objects that no Terraform resource owns.

Some objects are created by controllers. A Service of type LoadBalancer makes the cloud provider create a load balancer and public IP in the node resource group. Delete the Service and wait for those objects to disappear; delete the cluster first and they can outlive it.

The resource group is a useful audit gate. A resource group that still contains a cloud-created load balancer, disk or network interface will refuse deletion while the safety check is enabled. That refusal is the audit working, not a bug to route around.

Lab

Verify One Workload and Respect Teardown Order

Execution status: design-only. These steps are a lab plan; no live subscription output is recorded here, and every identifier is written as a token rather than a real value.

Prerequisites. Terraform 1.17.1, azurerm 5.13.0 and kubernetes 3.5.0, one sandbox subscription, a VNet with a pod subnet and a private DNS zone for the registry, permission to push one image, and permission to create role assignments. Use a digest you pushed yourself; nothing here depends on a public image.

BoundaryOwner rootProof it holds
registry and digestregistry rootthe deployment names a digest that exists in the repository
kubelet pullcluster rootthe pod reaches Running with no image pull error
workload tokenworkload rootone permitted call succeeds, one unrelated call is denied
namespaced objectsworkload rootdestroy removes the Service before the cluster exists to be deleted
  1. Create the registry with its network default set to deny, connect it to the private endpoint from the network root, push one image through the build identity, and record the digest. Confirm the cluster root plans no registry change.
  2. Apply the cluster root with the OIDC issuer and workload identity enabled, the chosen endpoint exposure, one system pool and one bounded user pool.
  3. Read back the API host, certificate authority and issuer. Authenticate as the deploy identity and confirm it cannot list nodes outside its namespace.
  4. Run the readiness probe until the API answers and every node reports Ready. Do not plan the workload root before this passes.
  5. Apply the workload root: namespace, annotated service account, deployment by digest, and a ClusterIP service.
  6. Exec into the pod and call one Azure resource the role assignment allows, then one it does not.
  7. Scale the deployment to zero and confirm the ClusterIP service created no load balancer. In a branch, add a LoadBalancer service and watch the object appear in the node resource group.
  8. Destroy the workload root and confirm the Service and its cloud objects are gone before destroying the cluster root.

Expected observation. Each step moves one boundary. The identity test changes what the pod may call without touching the image, the pull test changes registry access without touching the role assignment, and the workload destroy removes Kubernetes objects before the cluster that hosts them.

Failure checks. The lab fails if the pod can call an API its identity does not grant, if a load balancer or public IP survives the workload destroy, if the cluster destroy leaves disks or network interfaces behind, or if a second private DNS record set appears for the registry.

Cleanup order. Workload objects, then Services of type LoadBalancer, then persistent volume claims, then node pools, then the cluster, then registry images and the repository, then the private endpoint and DNS records. Check the load balancer, disk and network interface views after each stage rather than only at the end, and give the controller time to finish before deciding an object is stranded.

Evidence to keep. The approved digest, the service account and federated subject, one permitted and one denied API result, the pull failure message, and the cleanup audit with the time each residual object disappeared.

Next in the Series

In Key Vault and Managed Identity: Permissions, Secret Persistence and Recovery, we'll explore Separate secure storage, caller authorization and Terraform artifact exposure.