QA
Senior LevelDocker & Deployment

How do you configure Prometheus Adapter to expose custom application metrics to the HPA?

❓ Interview Prompt: Explain the Custom Metrics API pipeline: Prometheus → Prometheus Adapter → Custom Metrics API → HPA, and PromQL query configuration.

Standard HPA scales on CPU/RAM (from Metrics Server). Prometheus Adapter bridges Prometheus metrics to the Kubernetes Custom Metrics API — enabling HPA to scale on any business metric collected by Prometheus.

Full Pipeline:

App exposes /metrics → Prometheus scrapes → Prometheus Adapter queries PromQL → Custom Metrics API → HPA reads → Scales Deployment

Prometheus Adapter Configuration:

Adapter config maps PromQL queries to Custom Metrics API paths. The seriesQuery identifies which Prometheus series to expose. The metricsQuery computes the value per pod/namespace.

Common Custom Metrics for HPA:

•
HTTP requests/second: rate(http_requests_total[2m])
•
Queue depth: rabbitmq_queue_messages_ready
•
Active WebSocket connections: websocket_connections_active
•
Database query latency: histogram_quantile(0.95, ...)
•
Cache miss rate: rate(cache_misses_total[5m]) / rate(cache_requests_total[5m])

Why Not Just Use CPU for Scaling:

HTTP request count is a leading indicator — scale up BEFORE CPU spikes. CPU is a lagging indicator — by the time CPU is high, users are already experiencing latency.

Code Implementation Example

yaml
# Prometheus Adapter ConfigMap — maps PromQL to Custom Metrics API
apiVersion: v1
kind: ConfigMap
metadata:
  name: adapter-config
  namespace: monitoring
data:
  config.yaml: |
    rules:
      # Expose http_requests_per_second as a custom metric
      - seriesQuery: 'http_requests_total{namespace!="",pod!=""}'
        resources:
          overrides:
            namespace:
              resource: namespace
            pod:
              resource: pod
        name:
          matches: "^(.*)_total$"
          as: "${1}_per_second"
        metricsQuery: 'rate(<<.Series>>{<<.LabelMatchers>>}[2m])'

---
# HPA using the custom metric
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-hpa-custom
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 2
  maxReplicas: 50
  metrics:
    # Scale when average HTTP RPS > 100 per pod
    - type: Pods
      pods:
        metric:
          name: http_requests_per_second   # from Prometheus Adapter
        target:
          type: AverageValue
          averageValue: "100"   # 1 replica per 100 req/s
💡Prometheus Adapter exposes rate(http_requests_total) as custom metric — HPA scales to maintain 100 req/s per pod average.
🎯 Interview Key Takeaway

Prometheus Adapter translates PromQL queries to Custom Metrics API — HPA can scale on any application metric. HTTP RPS is a leading indicator; always prefer business metrics over lagging CPU for autoscaling.

#Prometheus Adapter#Custom Metrics#HPA#Autoscaling#Prometheus#Senior
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?