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

Custom Metrics for HPA

Configuring HPA with custom metrics from external sources, using the custom metrics API for application-specific scaling.

Custom Metrics for HPA

What you'll learn: How to scale your Kubernetes workloads based on application-specific metrics beyond CPU and memory using the custom metrics API.

Beyond CPU and Memory

So far, you've scaled pods using CPU or memory thresholds, but what if your application's performance depends on something else—like queue depth, HTTP request latency, or active database connections? That's where custom metrics come in.

The Horizontal Pod Autoscaler can integrate with external monitoring systems (like Prometheus) through the custom metrics API. This API adapter translates your application-specific metrics into a format HPA understands, allowing you to scale based on real business logic.

How It Works

Think of it like a translator at a conference: your monitoring system speaks one language (Prometheus queries), HPA speaks another (Kubernetes metrics API), and the custom metrics adapter translates between them in real-time.

Here's the flow:

  1. Your application exposes custom metrics (e.g., http_requests_per_second)
  2. A metrics collector (like Prometheus) scrapes and stores these metrics
  3. A custom metrics API adapter (like prometheus-adapter or keda) queries the collector
  4. HPA reads from this API and scales your pods accordingly

Configuration Pattern

Instead of targetCPUUtilizationPercentage, you reference custom metrics by name and type. The HPA watches these values and applies your scaling rules just like it does with CPU—it's the same autoscaling engine, just fed with different data.

This enables application-aware autoscaling: scale your order-processing pods based on pending orders, your API pods based on request queue depth, or your streaming service based on active connections.

Key Takeaway: Custom metrics for HPA let you scale pods based on application-specific indicators by integrating external metrics sources through the custom metrics API, enabling intelligent, business-logic-driven autoscaling beyond simple resource utilization.