Volume 8 · Chapter 6 — Azure Cloud Architecture & Enterprise DevOps for .NET Engineers
Azure Kubernetes Service (AKS) Advanced
6.1 Introduction
AKS is Azure’s managed Kubernetes: Microsoft operates the control plane (API server, scheduler, etcd) for free, while you manage the worker nodes and your workloads. It brings Kubernetes’ power - declarative deployment, self-healing, autoscaling, service discovery - without the burden of running the control plane yourself. This chapter covers the production concerns that separate a demo cluster from an enterprise one: node pools, networking, autoscaling, security, and CI/CD integration.
6.2 AKS Architecture
flowchart TB
subgraph Managed["Azure-managed Control Plane (free)"]
API["API Server"]
Sched["Scheduler"]
Etcd["etcd"]
end
subgraph Yours["Your Node Pools (you pay + manage)"]
SysPool["System node pool\n(CoreDNS, ingress)"]
AppPool["User node pool\n(app pods)"]
SpotPool["Spot node pool\n(batch, cheap)"]
end
API --> SysPool
API --> AppPool
API --> SpotPool 6.3 Core Kubernetes Objects
APodis the smallest deployable unit (one or more containers sharing a network namespace). ADeploymentmanages a replica set of pods and provides rolling updates and rollback. AServicegives a stable virtual IP and DNS name to a set of pods, and anIngressroutes external HTTP traffic to services.
// A Deployment manifest (YAML) defining replicas, resources, and probes.
// apiVersion: apps/v1
// kind: Deployment
// spec:
// replicas: 3
// template:
// spec:
// containers:
// - name: payments-api
// image: acr.azurecr.io/payments-api:1.4.2
// resources:
// requests: { cpu: "250m", memory: "256Mi" } # scheduling + HPA basis
// limits: { cpu: "500m", memory: "512Mi" } # hard cap
// livenessProbe: { httpGet: { path: /health/live, port: 8080 } }
// readinessProbe: { httpGet: { path: /health/ready, port: 8080 } }
6.4 Node Pools
Node pools let you run different workloads on different VM types. A common pattern separates a system pool (cluster services) from user pools (your apps), and adds specialized pools - GPU nodes for ML, memory-optimized for caches, or cheap Spot nodes for interruptible batch work. Pools scale and upgrade independently.
6.5 Networking: kubenet vs Azure CNI
AKS networking determines how pods get IPs and communicate. Azure CNI gives each pod a real VNet IP, enabling direct integration with VNet resources, private endpoints, and network policies - the enterprise default despite consuming more address space. Ingress controllers (NGINX, Application Gateway Ingress Controller) route external traffic, and network policies enforce pod-to-pod segmentation.
6.6 Autoscaling: HPA, Cluster Autoscaler, and KEDA
AKS scales at multiple levels. The Horizontal Pod Autoscaler adds pod replicas based on CPU/memory or custom metrics. The Cluster Autoscaler adds nodes when pods cannot be scheduled. KEDA scales pods on event sources (queue length, Service Bus) including to zero. Together they let the cluster track demand from event-driven bursts up to sustained load.
sequenceDiagram autonumber participant Q as Queue depth rises participant KEDA as KEDA / HPA participant Dep as Deployment participant CA as Cluster Autoscaler participant Nodes as Node Pool Q->>KEDA: metric: 5000 messages KEDA->>Dep: scale pods 3 -> 20 Dep->>Nodes: 20 pods need scheduling Nodes--xDep: insufficient capacity Dep->>CA: pending pods CA->>Nodes: add nodes Nodes-->>Dep: pods scheduled
6.7 Security
Production AKS security combines Entra ID integration for cluster access with Kubernetes RBAC, workload identity so pods authenticate to Azure services without secrets, network policies for pod segmentation, private clusters (no public API endpoint), image scanning and signed images, and secrets sourced from Key Vault via the CSI driver rather than stored in the cluster. Pod security standards restrict what containers may do.
6.8 Observability and CI/CD
Container Insights and managed Prometheus/Grafana provide metrics and logs; each service should expose OpenTelemetry traces. Deployment is automated through pipelines that build and scan an image, push it to Azure Container Registry, and apply manifests (or Helm charts / GitOps with Flux) to the cluster with a rolling or canary strategy.
Why use AKS instead of running Kubernetes yourself?
AKS removes the hardest and riskiest part of Kubernetes - operating the control plane. Microsoft runs and patches the API server, scheduler, and etcd (at no charge for the control plane), handles its availability, and integrates the cluster with Azure identity, networking, monitoring, Key Vault, and Container Registry. You keep control of node pools and workloads but shed the operational toil and expertise needed to run control-plane HA, upgrades, and backups safely. Self-managing Kubernetes only makes sense when you need capabilities or portability AKS cannot provide; for teams on Azure, AKS delivers Kubernetes’ power with dramatically less operational burden and better native security integration.
What is the difference between the Horizontal Pod Autoscaler and the Cluster Autoscaler?
They scale different things and work together. The Horizontal Pod Autoscaler (HPA) adjusts the number of pod replicas in a Deployment based on metrics like CPU, memory, or custom/event metrics - it answers “how many copies of my app should run?” The Cluster Autoscaler adjusts the number of nodes in a node pool - it answers “is there enough hardware to schedule those pods?” When HPA scales pods up and there is insufficient node capacity, pods go Pending and the Cluster Autoscaler adds nodes; when demand falls, HPA removes pods and the Cluster Autoscaler removes now-idle nodes. KEDA extends HPA to scale on external event sources (including to zero). You need both because scaling pods is pointless without the nodes to run them.
Why do resource requests and limits matter in Kubernetes?
Requests and limits govern scheduling, stability, and fairness. The request is the amount the scheduler reserves for a pod and the basis the HPA uses, so setting it too low overcommits nodes and causes contention, while too high wastes capacity. The limit is a hard ceiling: exceeding a memory limit gets the container OOM- killed, and exceeding a CPU limit throttles it. Without limits, a single misbehaving pod can starve its neighbors (the “noisy neighbor” problem); without correct requests, the scheduler makes bad placement decisions and autoscaling misfires. Setting them from real usage data is essential for a stable, efficiently packed, and autoscaling cluster.
How should pods authenticate to Azure services like Key Vault or SQL from AKS?
With Workload Identity, not stored secrets. Workload Identity federates a Kubernetes service account with an Entra ID managed identity, so a pod gets Entra tokens to call Azure services (Key Vault, SQL, Storage) without any credential in the cluster or code - the same secretless, least-privilege model as managed identities on VMs. Secrets that must exist (third-party API keys) are pulled from Key Vault at runtime via the Secrets Store CSI driver rather than baked into images or Kubernetes Secrets. This avoids long-lived credentials in manifests or config, gives per-workload least-privilege access, and lets the platform rotate tokens automatically.
How do you design a production-grade, multi-team AKS platform?
I treat AKS as a platform product with guardrails, not a shared free-for-all. I separate concerns with node pools (system vs user vs spot/specialized) and isolate teams and environments with namespaces plus resource quotas and network policies, so one team cannot starve or reach into another. Security is baked in: private cluster with no public API endpoint, Entra ID + Kubernetes RBAC for access, Workload Identity for secretless pod-to-Azure auth, Key Vault via the CSI driver, pod security standards, and image scanning/signing in the pipeline. Networking uses Azure CNI for VNet integration and an ingress controller with WAF. Autoscaling combines HPA/KEDA with the Cluster Autoscaler, and I set sane requests/limits and Pod Disruption Budgets so scaling and upgrades are safe. Delivery is GitOps or pipeline-driven with rolling/canary deploys, and observability (managed Prometheus/ Grafana, Container Insights, OpenTelemetry) is standard. I codify all of it as IaC and platform templates so teams deploy onto a governed, self-service platform rather than hand-crafting clusters. The goal is developer self-service within strong, automated guardrails.
How do you perform zero-downtime deployments and safe upgrades on AKS?
Zero-downtime comes from Kubernetes’ rolling-update mechanics done correctly plus progressive delivery. For app deploys, a Deployment’s rolling update replaces pods gradually while readiness probes gate traffic - a new pod receives requests only once it reports ready, and old pods drain their in-flight requests during a graceful termination window, so no request is dropped. I set Pod Disruption Budgets so voluntary disruptions (node upgrades, scale-down) never take too many replicas at once, and use multiple replicas across zones. For riskier changes I layer canary or blue-green (via a service mesh or two deployments behind weighted routing) so a bad version is exposed to a small slice and rolled back instantly. For cluster/node upgrades, AKS cordons and drains nodes respecting PDBs and readiness, and I upgrade node pools in a controlled, surge-capacity manner. The combination of readiness probes, graceful shutdown, PDBs, multi-zone replicas, and progressive rollout is what makes both application and platform changes non-disruptive.
6.9 Banking Enterprise Scenario
A bank runs its microservices on a private AKS cluster with no public API endpoint, integrated with Entra ID for access and Workload Identity so pods reach Key Vault and Azure SQL with no stored secrets. A system node pool hosts cluster services, a user pool runs the payment and account services with tuned requests/limits and Pod Disruption Budgets, and a spot pool runs overnight batch reconciliation cheaply. KEDA scales settlement consumers on Service Bus queue depth, backed by the Cluster Autoscaler for node capacity. Deployments flow through a pipeline that scans and signs images, pushes to ACR, and rolls out via readiness-gated updates with a canary step. Container Insights and managed Prometheus provide observability, meeting the bank’s reliability and security bar.
Chapter Revision Notes
- AKS manages the control plane; you manage node pools and workloads.
- Use node pools to separate system, app, and specialized/spot workloads.
- Azure CNI is the enterprise networking default; use network policies for segmentation.
- HPA/KEDA scale pods, Cluster Autoscaler scales nodes - you need both.
- Set requests/limits and PDBs; use Workload Identity for secretless Azure access.
- Achieve zero-downtime with readiness probes, graceful shutdown, and progressive rollout.