I am managing a cluster where some microservices have unpredictable traffic spikes while others are just memory-hungry during data processing. I’m confused about whether I should implement the Horizontal Pod Autoscaler (HPA) or the Vertical Pod Autoscaler (VPA). Can they be used together on the same set of pods, or will they conflict with each other and cause cluster instability?
3 answers
The general rule in Kubernetes is that you should not use HPA and VPA together on the same resource metrics (like CPU or Memory). If HPA is trying to add more pods based on CPU and VPA is trying to increase the CPU of the existing pods, they will fight each other, leading to "flapping" and resource waste. HPA is best for stateless apps that scale out easily with traffic. VPA is great for stateful jobs or "thick" applications where you can't easily distribute the load. If you must use both, set HPA to track a custom metric (like request count) while VPA manages the resource limits.
If we use VPA, how do we handle the fact that it has to restart the pods to update the resource limits?
For most web applications, HPA is the safer bet. It's much more mature and handles sudden traffic surges much better than VPA does.
Agreed, Ashley. I’ve found that VPA is a bit too slow for real-time spikes, whereas HPA spinning up 10 new pods is almost instantaneous.
That is the main drawback of VPA, Gregory. Unlike HPA, which is non-disruptive, VPA's "Auto" mode kills the pod to recreate it with the new specs. To avoid downtime, you need to ensure your PodDisruptionBudgets are correctly configured. Alternatively, look into the "In-place Pod Vertical Scaling" feature introduced in recent K8s versions, which allows updating resources without a restart, though it’s still somewhat experimental and requires specific container runtime support to work reliably.