1---2name: aks-kubernetes3description: Use when designing Azure Kubernetes Service (AKS) clusters, configuring node pools, integrating Azure AD/Entra ID RBAC, implementing Workload Identity, planning scaling strategies, or studying for AZ-400 or AZ-305.4---56# AKS Kubernetes78## When to Use9- Designing AKS cluster architecture (node pools, networking, identity)10- Configuring Azure AD/Entra ID integration for Kubernetes RBAC11- Implementing Workload Identity for pod-level Azure service authentication12- Planning cluster scaling strategy (Cluster Autoscaler, HPA, KEDA, Virtual Nodes)13- Choosing between kubenet and Azure CNI networking14- Preparing for Azure DevOps Engineer Expert (AZ-400) or Azure Solutions Architect Expert (AZ-305) exam1516## Core Jobs1718### 1. Node Pool Design19| Pool Type | Required | Purpose |20|-----------|----------|---------|21| **System node pool** | Yes | Runs kube-system pods (CoreDNS, metrics-server); cannot be deleted |22| **User node pool** | No | Runs application workloads; multiple allowed; can be deleted |2324- Isolate workloads: separate node pools for GPU workloads, Windows containers, or spot instances25- Node pool VM sizes: choose based on workload (General Purpose, Memory Optimized, GPU)26- **Spot node pools**: low-cost; can be evicted; use for fault-tolerant, batch workloads only27- System node pool: cannot have 0 nodes; minimum 1 system node pool required2829### 2. Entra ID Integration and RBAC30- **Azure AD/Entra ID-integrated AKS**: authenticate to cluster using Entra tokens (`kubelogin`)31- `kubectl` commands require Entra ID authentication; `kubeconfig` uses AAD tokens32- Two RBAC modes:33 - **Azure RBAC for K8s**: manage K8s RBAC with Azure role assignments (`Azure Kubernetes Service RBAC Admin`, etc.)34 - **K8s RBAC + Entra groups**: map Entra groups to K8s `ClusterRoleBinding`/`RoleBinding`35- Entra group membership synced automatically; add user to group → gets K8s access3637### 3. Workload Identity38- **Workload Identity** = recommended method to give pods Azure service access without credentials39- Replaces deprecated **AAD Pod Identity** (v1 approach)40- Architecture:41 1. Create **User-assigned Managed Identity** in Azure42 2. Create **Kubernetes ServiceAccount** with Workload Identity annotation43 3. Create **Federated identity credential** linking ServiceAccount to Managed Identity44 4. Assign RBAC role to Managed Identity on target Azure resource45 5. Pod uses ServiceAccount → SDK gets token via OIDC → Azure authenticates Managed Identity46- Use `DefaultAzureCredential` in pod code; automatically picks up Workload Identity token4748### 4. Scaling Strategies49| Scaler | Scope | Trigger |50|--------|-------|---------|51| **Cluster Autoscaler** | Node (VM) level | Pending pods that can't be scheduled |52| **HPA (Horizontal Pod Autoscaler)** | Pod level | CPU/memory metrics (or custom metrics) |53| **VPA (Vertical Pod Autoscaler)** | Pod resource limits | Right-sizes CPU/memory requests |54| **KEDA** | Pod level (event-driven) | External metrics: queue depth, Event Hub lag |55| **Virtual Nodes** | Pod burst to ACI | Overflow scheduling to Azure Container Instances |5657- For full autoscaling: enable both **Cluster Autoscaler** (nodes) + **HPA or KEDA** (pods)58- **Virtual Nodes**: burst to ACI for sudden traffic spikes; ACI pods billed per-second; no node capacity needed59- **KEDA** = Kubernetes Event-Driven Autoscaling; scales to zero based on external event sources (Service Bus, Event Hubs, Kafka)6061### 5. Networking: kubenet vs Azure CNI62| Aspect | kubenet | Azure CNI |63|--------|---------|-----------|64| Pod IPs | Private range (not VNet IPs) | VNet IPs assigned to pods |65| VNet address planning | Small VNet sufficient | VNet must have IP for every possible pod |66| Network policies | Limited (Calico only) | Full (Azure Network Policy + Calico) |67| Best for | Dev/test, simple scenarios | Enterprise, network policies, peering |68| Private Link access | Requires extra routing | Direct (pods have VNet IPs) |6970- Azure CNI = pods reachable directly from VNet (and peered VNets); required for most enterprise scenarios71- kubenet = pods behind NAT; simpler but limited network policy support7273### 6. Azure Policy for AKS74- **Azure Policy + Gatekeeper (OPA)**: enforce pod security standards at admission time75- Built-in policies: restrict privileged containers, enforce resource limits, require pod labels76- Applied at cluster level; blocks non-compliant deployments before they create pods77- **Pod Security Standards**: Baseline (moderate restrictions) and Restricted (strict, production-ready)78- Audit mode: report violations without blocking; Enforce mode: block at deployment7980## Key Concepts81- **Workload Identity** — federated OIDC-based pod identity; recommended; replaces Pod Identity (deprecated)82- **Cluster Autoscaler** — adds/removes nodes based on pending pod scheduling; works with node pools83- **KEDA** — event-driven pod autoscaler; scales to zero based on queue/stream metrics84- **Virtual Nodes** — burst scheduling to Azure Container Instances; no node billing; per-second ACI cost85- **Azure CNI** — pods get VNet IPs; required for network policies and VNet peering access to pods86- **System node pool** — mandatory; runs cluster control components; cannot be deleted87- **kubelogin** — Azure plugin for `kubectl`; converts AAD tokens for Kubernetes API authentication8889## Checklist90- [ ] System node pool separated from application (user) node pools?91- [ ] Workload Identity configured for pods that need Azure service access (not AAD Pod Identity)?92- [ ] Azure CNI networking selected for enterprise deployments needing network policies?93- [ ] Cluster Autoscaler enabled + HPA or KEDA for full autoscaling coverage?94- [ ] Azure Policy + Gatekeeper configured to enforce pod security standards?95- [ ] Entra ID integration enabled; local admin accounts disabled where possible?96- [ ] Spot node pools used only for fault-tolerant workloads (with tolerations)?9798## Output Format99- 🔴 **Critical** — AAD Pod Identity used (deprecated; migrate to Workload Identity)100- 🔴 **Critical** — all workloads on system node pool (risks cluster stability; kube-system pods may be evicted)101- 🟡 **Warning** — kubenet networking in enterprise deployment with network policy requirement (use Azure CNI)102- 🟡 **Warning** — only Cluster Autoscaler without HPA (nodes scale but pods don't; wastes capacity)103- 🟢 **Suggestion** — enable KEDA for event-driven workloads (Service Bus consumers) to scale pods to zero104105## Exam Tips106- **Workload Identity = recommended** — replaces AAD Pod Identity which is deprecated; uses OIDC federation with ServiceAccount107- **Azure CNI = pods get VNet IPs** — kubenet = pods behind NAT; CNI required for network policies and direct VNet access to pods108- **Virtual Nodes = burst to ACI** — schedule pods on ACI for cost-effective burst capacity; no node VM required; per-second billing109- **System node pool = required; cannot be deleted** — runs kube-system pods; minimum 1 required in every AKS cluster110- **Cluster Autoscaler scales nodes; HPA scales pods** — both needed for complete autoscaling; Cluster Autoscaler reacts to pending pods111- **AKS Managed Identity** — cluster identity for Azure resource access (attach disks, update load balancers); no service principal needed in modern AKS