Introduction
When HPA fails to scale applications automatically, it defeats the purpose of Kubernetes elasticity. This guide covers metrics-server configuration and HPA policy tuning.
Symptoms
- kubectl top nodes/pods shows no metrics
- HPA shows <unknown> for current metrics
- No scaling events despite high load
- Target showing 0%/N%
Step-by-Step Fix
- 1.Verify metrics-server is running:
- 2.```bash
- 3.kubectl get pods -n kube-system | grep metrics-server
- 4.kubectl top nodes
- 5.
` - 6.Check HPA status:
- 7.```bash
- 8.kubectl describe hpa <hpa-name>
- 9.kubectl get hpa <hpa-name> -o yaml
- 10.
` - 11.Verify resource requests are set:
- 12.```yaml
- 13.resources:
- 14.requests:
- 15.cpu: "100m"
- 16.memory: "128Mi"
- 17.
` - 18.Configure HPA with proper thresholds:
- 19.```yaml
- 20.apiVersion: autoscaling/v2
- 21.kind: HorizontalPodAutoscaler
- 22.spec:
- 23.scaleTargetRef:
- 24.apiVersion: apps/v1
- 25.kind: Deployment
- 26.name: my-app
- 27.minReplicas: 2
- 28.maxReplicas: 20
- 29.metrics:
- 30.- type: Resource
- 31.resource:
- 32.name: cpu
- 33.target:
- 34.type: Utilization
- 35.averageUtilization: 70
- 36.behavior:
- 37.scaleUp:
- 38.stabilizationWindowSeconds: 60
- 39.policies:
- 40.- type: Percent
- 41.value: 100
- 42.periodSeconds: 15
- 43.
`