Stage 10, Part 3 of 9, Autoscaling & Cost Optimization

Text

PART 3: PRODUCTION FAILURE MODES

14. Top 10 Autoscaling & Cost Failures

#FailureSymptomRoot CauseFix
1PDB blocks scale-downNodes never removedPDB prevents evictionAdjust PDB
2HPA/VPA conflictUnstable replicasBoth scale on CPUSeparate metrics
3Inflated requestsCluster appears busyRequests >> usageVPA rightsizing
4Karpenter consolidation stormConstant node churnConsolidation too aggressiveTune consolidation policy
5Spot interruption cascadeMultiple pods evictedAll replicas on same spot poolDiversify, PDB
6HPA metric unavailableHPA doesn't scaleCustom metrics API downFix metrics adapter
7KEDA scaler misconfigurationScale to zero unexpectedlyWrong metric thresholdTune scaler
8Cluster Autoscaler slowPods Pending for minutes3-4 minute provisioningMigrate to Karpenter
9Cost anomalyUnexpected bill spikeRunaway workload, no limitsSet limits, alerts
10Bin-packing breaks HASingle node failure kills serviceOver-consolidationPod anti-affinity

The PDB Deadlock (Real Production Lesson)

A PDB defines how many pods must remain available during voluntary disruptions. In one production case, CPU utilization across nodes was very low, but the cluster was not scaling down. The PDB configuration prevented Kubernetes from evicting the pods. Because the pods could not be evicted, the autoscaler was not allowed to remove the node. This type of configuration issue can cause nodes that never scale down, wasted compute resources, and significantly increased cloud costs in large clusters.


15. Autoscaling Debugging Runbook

“HPA isn’t scaling” — Step-by-Step

text
STEP 1: Check HPA status
  $ kubectl get hpa
  $ kubectl describe hpa <name>
  # Look at current metrics, desired replicas, conditions

STEP 2: Check metrics availability
  $ kubectl top pods
  $ kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes
  # If empty, metrics-server is down

STEP 3: Check resource requests
  $ kubectl get deployment <name> -o jsonpath='{.spec.template.spec.containers[*].resources.requests}'
  # HPA uses requests for CPU utilization %

STEP 4: Check HPA events
  $ kubectl get events --field-selector involvedObject.name=<hpa-name>

STEP 5: Check custom metrics (if used)
  $ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1

STEP 6: Check behavior policies
  $ kubectl get hpa <name> -o yaml | grep -A20 behavior
  # Stabilization windows may be blocking

STEP 7: Escalate

“Cluster isn’t scaling down” — Step-by-Step

text
STEP 1: Check node utilization
  $ kubectl top nodes

STEP 2: Check PDBs
  $ kubectl get pdb -A
  $ kubectl describe pdb <name>
  # PDB may be blocking eviction

STEP 3: Check Cluster Autoscaler logs
  $ kubectl logs -n kube-system -l app=cluster-autoscaler --tail=100

STEP 4: Check Karpenter logs (if using Karpenter)
  $ kubectl logs -n karpenter -l app.kubernetes.io/name=karpenter --tail=100

STEP 5: Check for pods that can't be evicted
  $ kubectl get pods -A --field-selector status.phase=Running
  # Look for pods without controllers (bare pods)

STEP 6: Check node annotations
  $ kubectl describe node <node> | grep -A5 "Annotations"

STEP 7: Escalate

16. Blast Radius Analysis

What Happens When Autoscaling Fails?

ComponentImpactSeverity
HPA downNo replica scaling; capacity fixedSEV-2
VPA downNo rightsizingSEV-3
KEDA downNo event-driven scalingSEV-2
Karpenter downNo node provisioningSEV-1
Cluster Autoscaler downNo node scalingSEV-1
Cost monitoring downNo visibilitySEV-3
PDB blocking scale-downWasted costSEV-3

Mitigation Strategies

StrategyImplementation
HA autoscalersMultiple replicas
FallbackOn-demand node groups
MonitoringAlerts on scaling events
Cost alertsBudget alerts
TestingChaos engineering for scaling

1:1 copy of the class Google Doc, code in code blocks.