This repository contains reusable Terraform modules, per-environment stacks, and Kustomize overlays for standing up an Azure Kubernetes Service (AKS) platform with its core dependencies (networking, Azure Container Registry, RBAC wiring) and shipping baseline Kubernetes manifests.
| Path | Description |
|---|---|
infra/terraform/modules/network |
Virtual network, subnet, and resource group definitions shared by all environments. |
infra/terraform/modules/acr |
Azure Container Registry with deterministic naming + tags. |
infra/terraform/modules/aks |
AKS cluster, system node pool, two user pools, autoscaler toggles, and kubelet identity outputs. |
infra/terraform/envs/dev |
Root module that wires modules together and assigns the AcrPull role. Duplicate this folder for new environments. |
infra/k8s/base |
Base Kubernetes manifests expressed as Kustomize resources. |
infra/k8s/overlays/dev |
Dev-specific patches layered over the base manifests. |
scripts/bootstrap.sh |
Helper script stub for future automation (credentials, tooling, etc.). |
- Terraform >= 1.5
- Azure CLI authenticated against the target subscription
- Remote state storage prepared (Azure Storage account + container)
- Sufficient RBAC permissions to create resource groups, VNETs, AKS, and ACR resources
-
Navigate to the dev stack:
cd infra/terraform/envs/dev -
Initialize Terraform with your backend settings:
terraform init \ -backend-config="resource_group_name=<rg>" \ -backend-config="storage_account_name=<storage>" \ -backend-config="container_name=<container>" \ -backend-config="key=dev.terraform.tfstate"
-
Review variables in
terraform.tfvars(name prefix, location, VM sizes, autoscaler bounds) and adjust as needed. -
Plan and apply:
terraform plan -out tfplan terraform apply tfplan
-
Retrieve cluster credentials once Terraform completes:
az aks get-credentials \ --resource-group <rg> \ --name <cluster-name>
-
Deploy Kubernetes addons using Kustomize (example for dev):
cd ../../k8s/overlays/dev kustomize build . | kubectl apply -f -
- Networking:
/16VNET with/24subnet reserved for AKS; edit CIDRs inmodules/network/variables.tfif needed. - Node Pools:
systempool restricts workloads to critical addons. Two user pools (user1,user2) can scale independently with autoscaler toggles exposed via variables. - ACR Integration:
azurerm_role_assignmentensures the AKS kubelet identity hasAcrPullpermissions against the registry provisioned in the same resource group. - Tagging: All modules accept
var.tagsto enforce consistent metadata (cost center, environment, owner, etc.).
- Copy
infra/terraform/envs/devto a new folder (e.g.,stage). - Update
terraform.tfvarswith the new environment name, backend key, and sizing. - Optionally create a matching Kustomize overlay under
infra/k8s/overlays/<env>to hold environment-specific manifests.
- Ensure the subnet has enough IPs for planned scale; adjust
address_prefixesif pods fail to schedule. - When changing AKS VM sizes, keep the
temporary_name_for_rotationfield populated to avoid rotation errors. - Use
terraform state listto confirm resources before destructive operations. - For pull errors from ACR, verify that the role assignment in the root module completed and that the kubelet identity matches the AKS cluster’s managed identity.
- Add monitoring/logging modules (Azure Monitor, Log Analytics) under
infra/terraform/modules. - Grow the Kustomize base with core platform workloads (ingress, cert-manager, policy controllers).
- Integrate CI/CD to lint Terraform, enforce
terraform fmt, and runkustomize buildsmoke checks.