HorizontalPodAutoscaler scales deployment replicas up or down based on CPU or memory utilisation.
Horizontal Pod Autoscaler
# HPA — scale pods based on CPU/memory
kubectl autoscale deployment myapp --cpu-percent=70 --min=2 --max=10
# hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
kubectl get hpa
kubectl describe hpa myapp-hpa