Skip to main content

Overview

Horizontal Pod Autoscaling (HPA) automatically adjusts the number of Lightning ASR and API Server pods based on workload demand. This guide covers configuring HPA using custom metrics like active request count.

How HPA Works

Lightning ASR exports the asr_active_requests metric, which tracks the number of requests currently being processed. HPA uses this to scale pods up or down.

Prerequisites

1

Prometheus Stack

Install kube-prometheus-stack (included in Helm chart):
values.yaml
2

Prometheus Adapter

Install prometheus-adapter (included in Helm chart):
values.yaml
3

Service Monitor

Enable ServiceMonitor for Lightning ASR:
values.yaml

Enable HPA

Lightning ASR HPA

Configure autoscaling for Lightning ASR based on active requests:
values.yaml
Parameters:
  • minReplicas: Minimum number of pods (never scales below)
  • maxReplicas: Maximum number of pods (never scales above)
  • targetActiveRequests: Target active requests per pod (scales when exceeded)
  • scaleUpStabilizationWindowSeconds: Delay before scaling up (0 = immediate)
  • scaleDownStabilizationWindowSeconds: Delay before scaling down (prevents flapping)

API Server HPA

Configure autoscaling for API Server based on Lightning ASR replicas:
values.yaml
Parameters:
  • lightningAsrToApiServerRatio: Ratio of Lightning ASR to API Server pods (2 = 2 ASR pods per 1 API pod)

Advanced Scaling Behavior

Custom Scaling Policies

Fine-tune scaling behavior:
values.yaml
Scale Up Policies:
  • Add up to 100% more pods every 15 seconds
  • OR add up to 2 pods every 15 seconds
  • Use whichever is higher (selectPolicy: Max)
Scale Down Policies:
  • Remove up to 50% of pods every 60 seconds
  • OR remove up to 1 pod every 60 seconds
  • Use whichever is lower (selectPolicy: Min)

Multi-Metric HPA

Scale based on multiple metrics:

Verify HPA Configuration

Check HPA Status

Expected output:

Describe HPA

Look for:

Check Custom Metrics

Verify prometheus-adapter is providing metrics:
Should show asr_active_requests in the list. Query specific metric:

Testing HPA

Load Testing

Generate load to trigger scaling:
Watch scaling in action:

Monitor Pod Count

In another terminal:
You should see:
  1. Active requests increase
  2. HPA detects load above target
  3. New pods created
  4. Load distributed across pods
  5. After load decreases, pods scale down (after stabilization window)

Scaling Scenarios

Scenario 1: Traffic Spike

Situation: Sudden increase in requests HPA Response:
  1. Detects asr_active_requests > 5 per pod
  2. Immediately scales up (stabilization: 0s)
  3. Adds pods based on policy (2 pods or 100%, whichever is higher)
  4. Repeats every 15 seconds until load is distributed
Configuration:

Scenario 2: Gradual Traffic Decline

Situation: Traffic decreases after peak hours HPA Response:
  1. Detects asr_active_requests < 5 per pod
  2. Waits 300 seconds (5 minutes) before scaling down
  3. Gradually removes pods (1 pod or 50%, whichever is lower)
  4. Prevents premature scale-down
Configuration:

Scenario 3: Off-Hours

Situation: No traffic during night HPA Response:
  1. Scales down to minReplicas: 1
  2. Keeps one pod ready for incoming requests
  3. Scales up immediately when traffic resumes
Configuration:
For complete cost savings during off-hours, use Cluster Autoscaler to scale nodes to zero.

Troubleshooting

HPA Shows “Unknown”

Symptom:
Diagnosis: Check prometheus-adapter logs:
Check ServiceMonitor:
Check Prometheus is scraping:
Open http://localhost:9090 and query: asr_active_requests Solutions:
  1. Ensure ServiceMonitor is created
  2. Verify Prometheus is scraping Lightning ASR pods
  3. Check prometheus-adapter configuration

HPA Not Scaling

Symptom: Metrics show high load but pods not increasing Check:
Look for events explaining why scaling didn’t occur:
Common causes:
  • Metrics not available (see above)
  • Already at maxReplicas
  • Insufficient cluster resources
  • Stabilization window preventing scale-up

Pods Scaling Too Aggressively

Symptom: Pods constantly scaling up and down Solution: Increase stabilization windows:

Scale-Down Too Slow

Symptom: Pods remain after traffic drops Solution: Reduce scale-down stabilization:
Be careful: too aggressive scale-down causes flapping.

Best Practices

Choose targetActiveRequests based on your model performance:
  • Larger models (slower inference): Lower target (e.g., 3)
  • Smaller models (faster inference): Higher target (e.g., 10)
Test with load to find optimal value.
Scale up quickly, scale down slowly:
Prevents request failures during traffic fluctuations.
Consider cluster capacity when setting maxReplicas:
Don’t set higher than available GPU resources.
Use Grafana to visualize:
  • Current vs target metrics
  • Pod count over time
  • Scale-up/down events
See Grafana Dashboards
Regularly load test to verify HPA behavior:

What’s Next?

Cluster Autoscaler

Scale cluster nodes automatically

Metrics Setup

Configure Prometheus and custom metrics

Grafana Dashboards

Visualize metrics and scaling behavior