terraform-azure-aks

Azure Kubernetes Service Module Architecture

Azure Kubernetes

Executive Summary

Production-grade Terraform module for deploying Azure Kubernetes Service (AKS) clusters with enterprise features. Provisions a private AKS cluster with system/user node pools across three availability zones, Azure CNI Overlay networking with Cilium dataplane, workload identity (OIDC), Microsoft Defender for Containers, Azure Policy, Key Vault CSI driver, image cleaner, and integrated ACR pull access. Designed for organizations requiring a secure, scalable, GitOps-ready Kubernetes platform on Azure.

Overview Cards

Resources
3
AKS Cluster, Node Pools, ACR Role
Variables
21
6 required, 15 optional
Outputs
9
Cluster IDs, FQDN, Identities
Provider
azurerm
>= 3.80.0
Terraform
>= 1.5.0
HCL Configuration
Network
CNI + Cilium
Overlay mode, eBPF dataplane

Architecture Diagram

AKS Control Plane
Private API Server
System Node Pool
AZ1/AZ2/AZ3 - Critical Addons
User Node Pool(s)
General / GPU / Spot
Azure CNI Overlay
Cilium Network Policy + Dataplane
VNet Subnet
vnet_subnet_id
Workload Identity
OIDC Issuer
Microsoft Defender
Threat Detection
Azure Policy
Compliance
Key Vault CSI
Secret Rotation
Log Analytics
Container Insights / OMS
ACR Integration
AcrPull Role Assignment

Component Breakdown

ComponentResource TypePurposeConfiguration
AKS Clusterazurerm_kubernetes_clusterManaged Kubernetes control plane + default node poolPrivate, Standard SKU, SystemAssigned identity
Additional Node Poolsazurerm_kubernetes_cluster_node_poolUser workload node pools (GPU, spot, memory-optimized)for_each map, auto-scaling, taints/labels
ACR Pull Roleazurerm_role_assignmentGrants kubelet identity AcrPull on Container RegistryConditional on acr_id
Network ProfileInline blockAzure CNI Overlay + Cilium eBPFPod CIDR 10.244.0.0/16, Service CIDR 10.0.0.0/16
Workload IdentityInline featureOIDC-based pod identity federationEnabled by default
Key Vault CSIInline add-onMount Key Vault secrets into podsSecret rotation every 2m
DefenderInline blockRuntime threat detection for containersRequires Log Analytics
Maintenance WindowInline blockScheduled cluster maintenanceAllowed/not-allowed windows

Data Flow

1
Developer pushes container image to Azure Container Registry (ACR).
2
AKS kubelet identity pulls images from ACR via AcrPull role assignment.
3
Pods are scheduled on system or user node pools across availability zones.
4
Azure CNI Overlay with Cilium routes traffic; network policies enforce microsegmentation.
5
Workload Identity federates pod service accounts with Azure AD for passwordless Azure resource access.
6
Key Vault CSI driver injects secrets directly into pod volumes with auto-rotation.
7
OMS Agent ships logs/metrics to Log Analytics; Defender monitors for runtime threats.

Security Controls

ControlImplementationDefault
Private ClusterAPI server accessible only within VNetEnabled
RBACKubernetes RBAC + Azure AD RBACEnabled (always on)
Workload IdentityOIDC issuer + federated credentialsEnabled
Network PolicyCilium eBPF-based pod network policiesCilium
Microsoft DefenderRuntime threat detection, vulnerability scanningEnabled
Azure PolicyEnforce organizational standards on clustersEnabled
Key Vault IntegrationCSI driver with secret rotation (2m)Enabled
Image CleanerAutomatic stale image cleanup (48h)Enabled
API Server AccessAuthorized IP ranges whitelistOptional

Industry Adaptation

CapabilityHealthcareFinanceGovernmentRetailSaaS
Private Cluster
Azure Policy✓ HIPAA✓ PCI-DSS✓ FedRAMP
Defender
Workload Identity
Network Policy
Multi-AZ
Audit LoggingOptionalOptional

Production Readiness Checklist

Configuration Reference

VariableTypeDefaultDescription
cluster_namestringrequiredName of the AKS cluster
kubernetes_versionstringrequiredKubernetes version
vnet_subnet_idstringrequiredSubnet ID for default node pool
private_cluster_enabledbooltrueEnable private API server
sku_tierstringStandardFree, Standard, or Premium
network_policystringciliumNetwork policy engine
default_node_poolobjectrequiredSystem node pool configuration
additional_node_poolsmap(object){}User node pools map
enable_workload_identitybooltrueWorkload identity federation
enable_defenderbooltrueMicrosoft Defender for Containers
acr_idstringnullACR ID for AcrPull role

Deployment

# Initialize
terraform init

# Plan
terraform plan -out=tfplan \
  -var="cluster_name=my-aks" \
  -var="resource_group_name=rg-aks" \
  -var="location=eastus" \
  -var="kubernetes_version=1.29" \
  -var="dns_prefix=myaks" \
  -var='vnet_subnet_id=/subscriptions/.../subnets/aks'

# Apply
terraform apply tfplan

# Get credentials
az aks get-credentials --resource-group rg-aks --name my-aks

Links

Azure AKS Documentation | Terraform AKS Resource | Module README | Examples