Kubernetes Autoscaling
HPA, VPA, and Cluster Autoscaler for scaling pods and nodes.
Why
K8s autoscaling adjusts to demand: HPA scales pod replicas by CPU/memory/custom metrics, VPA adjusts resource requests, Cluster Autoscaler adds/removes nodes. Docker is used by 59% of professional developers per the Stack Overflow 2024 survey, and Kubernetes runs 60% of containerized workloads in production (CNCF 2024 survey).
Container orchestration reduces deployment-related incidents by 35% through declarative rollouts.
When
Use HPA for stateless web apps, VPA for resource right-sizing, Cluster Autoscaler for node scaling. Skip containers for simple static sites — a CDN + static export is cheaper and faster.
Avoid Kubernetes for teams under 10 people; the operational overhead is not justified.
How
Example
Common Problems
- ⚠HPA not scaling — metrics-server not installed, required for CPU/memory
- ⚠Thrashing — scale up/down too fast, set stabilizationWindowSeconds
- ⚠Configuration drift between environments — use infrastructure-as-code (Terraform/Pulumi) to keep dev/staging/prod identical
Best Practices
- ✓Set minReplicas > 0 — avoids scale to zero, use KEDA for zero-scaling
- ✓Use custom metrics for real load — CPU doesn't reflect queue depth or RPS
- ✓Set up health checks and graceful shutdown — handle SIGTERM to drain in-flight requests before exit