menu
Automatically scale down pods when CPU/RAM is low:

- Scales up: when pods are unschedulable due to lack of resources.
- Scales down: when nodes are underutilized and workloads can be moved elsewhere.

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-hpa
  namespace: dev
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 1
  maxReplicas: 3
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 60