Course contentsShow
← Cloud and Infrastructure
Lesson 1454 of 2,98929. Kubernetes ObservabilityFree lesson

Multiple Metrics in HPA

Combining CPU, memory, and custom metrics in a single HPA, understanding how Kubernetes evaluates multiple conditions.

Multiple Metrics in HPA

What you'll learn: How to configure an HPA that evaluates several metrics simultaneously and understand Kubernetes' decision-making process when multiple conditions exist.

The Core Concept

Up until now, you've seen HPAs that scale based on a single metric—CPU, memory, or perhaps one custom metric. But real-world applications often need more nuanced scaling logic. Kubernetes allows you to specify multiple metrics in a single HPA, giving you the flexibility to scale based on CPU and memory and custom application metrics all at once.

How Kubernetes Evaluates Multiple Metrics

When you define multiple metrics, Kubernetes doesn't average them or pick one at random. Instead, it calculates the desired replica count for each metric independently, then takes the highest value among all calculations.

Think of it like a team of advisors where each suggests a different number of replicas based on their specialty. The HPA listens to the most aggressive recommendation—the one calling for the most replicas—to ensure none of your thresholds are breached.

Example Scenario

Imagine your HPA monitors:

  • CPU: suggests 3 replicas
  • Memory: suggests 5 replicas
  • Custom metric (queue length): suggests 2 replicas

Kubernetes will scale to 5 replicas because memory demands the highest count.

Why This Matters

This "maximum of all metrics" approach ensures your application gets enough resources to handle any bottleneck, not just the average constraint. It's conservative but safe—you won't under-provision when one metric spikes while others are calm.

Key Takeaway: When combining multiple metrics in an HPA, Kubernetes evaluates each metric independently and scales to the highest calculated replica count, ensuring all resource thresholds are respected.