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. 1.Verify metrics-server is running:
  2. 2.```bash
  3. 3.kubectl get pods -n kube-system | grep metrics-server
  4. 4.kubectl top nodes
  5. 5.`
  6. 6.Check HPA status:
  7. 7.```bash
  8. 8.kubectl describe hpa <hpa-name>
  9. 9.kubectl get hpa <hpa-name> -o yaml
  10. 10.`
  11. 11.Verify resource requests are set:
  12. 12.```yaml
  13. 13.resources:
  14. 14.requests:
  15. 15.cpu: "100m"
  16. 16.memory: "128Mi"
  17. 17.`
  18. 18.Configure HPA with proper thresholds:
  19. 19.```yaml
  20. 20.apiVersion: autoscaling/v2
  21. 21.kind: HorizontalPodAutoscaler
  22. 22.spec:
  23. 23.scaleTargetRef:
  24. 24.apiVersion: apps/v1
  25. 25.kind: Deployment
  26. 26.name: my-app
  27. 27.minReplicas: 2
  28. 28.maxReplicas: 20
  29. 29.metrics:
  30. 30.- type: Resource
  31. 31.resource:
  32. 32.name: cpu
  33. 33.target:
  34. 34.type: Utilization
  35. 35.averageUtilization: 70
  36. 36.behavior:
  37. 37.scaleUp:
  38. 38.stabilizationWindowSeconds: 60
  39. 39.policies:
  40. 40.- type: Percent
  41. 41.value: 100
  42. 42.periodSeconds: 15
  43. 43.`