Let's think about it this way for a second
When traffic spikes, you want more pods — you can manually scale with `kubectl scale deployment web-deployment --replicas=10`, but if nobody scales it back down when traffic drops at midnight, you're just wasting resources. HPA (Horizontal Pod Autoscaler) monitors CPU/memory usage (or a custom metric) and automatically scales pods up when a target threshold is crossed, and back down when usage falls below it — so 'you don't have to babysit scaling yourself.'
Let's connect this to a real scenario
If you create an HPA with something like `kubectl autoscale deployment web-deployment --min=2 --max=10 --cpu-percent=70`, then once average CPU usage crosses 70%, it'll scale pods up to a max of 10, and scale back down to a minimum of 2 once load drops. To run HPA, you need the metrics-server add-on installed on the cluster (it's the component that supplies CPU/memory data).
Let's look at it together
# Manual scale
kubectl scale deployment web-deployment --replicas=10
# Create an HPA: 2-10 pods, target 70% CPU
kubectl autoscale deployment web-deployment \
--min=2 --max=10 --cpu-percent=70
# Watch HPA in action
kubectl get hpa web-deployment --watchNAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS
web-deployment Deployment/web-deployment 45%/70% 2 10 35-Minute Try-It
Create an HPA and watch the target/replicas with `kubectl get hpa --watch` (with no traffic, it'll just sit at the minimum replica count — that's normal).
A Quick Word of Caution
HPA calculates its percentage based on the CPU/memory 'requests' value — if you haven't set resource requests in the Pod spec, HPA won't be able to work properly.