Cloud Intermediate
Horizontal Pod Autoscaler¶
KubernetesAutoscalingHPA 3 min read
Automatic pod scaling based on CPU, memory or custom metrics.
Basic HPA¶
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api
minReplicas: 2
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
Custom Metrics¶
With Prometheus Adapter you can scale based on HTTP request rate, queue depth, etc.
Summary¶
HPA is the foundation of autoscaling. Always set requests (HPA needs them). Minimum 2 replicas for HA.
Need Help with Implementation?¶
Our team has experience designing and implementing modern architectures. We’re happy to help.