HPA — automatically scales Pod count based on metrics.
1apiVersion: autoscaling/v22kind: HorizontalPodAutoscaler3metadata:4 name: myapp-hpa5spec:6 scaleTargetRef:7 apiVersion: apps/v18 kind: Deployment9 name: myapp10 minReplicas: 211 maxReplicas: 2012 metrics:13 - type: Resource14 resource:15 name: cpu16 target:17 type: Utilization18 averageUtilization: 7019 - type: Resource20 resource:21 name: memory22 target:23 type: Utilization24 averageUtilization: 8025 - type: Pods26 pods:27 metric:28 name: http_requests_per_second29 target:30 type: AverageValue31 averageValue: "1000"32 - type: External33 external:34 metric:35 name: sqs_queue_length36 target:37 type: Value38 value: "30"39 behavior:40 scaleUp:41 stabilizationWindowSeconds: 6042 policies:43 - type: Percent44 value: 10045 periodSeconds: 6046 scaleDown:47 stabilizationWindowSeconds: 30048 policies:49 - type: Percent50 value: 1051 periodSeconds: 60
1# Commands2kubectl get hpa3kubectl describe hpa myapp-hpa4kubectl autoscale deployment myapp --min=2 --max=10 --cpu-percent=705kubectl top pods # Check current metrics
Metrics: