Min and max replicas
- Docker & Kubernetes course
- Advanced
- Lesson 40/70
- 4 min
Learn minReplicas and maxReplicas fields.
Min and max replicas
minReplicas is the base replica count kept even when load drops; for high availability, at least 2 is usually chosen. maxReplicas is the ceiling limiting cost and back-end (database) load. The calculated value is clipped to this range:
# calculated 14, maxReplicas 10
$ kubectl describe hpa api | grep ScalingLimited
ScalingLimited True TooManyReplicas the desired replica count is more than the maximum replica countScaling behaviour
The behavior field adjusts the speed of scaling. By default there's a 5-minute stabilization window for scaling down: pods aren't closed immediately on short dips (prevents flapping):
behavior:
scaleUp:
policies:
- type: Percent
value: 100 # at most double every 15 s
periodSeconds: 15
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Pods
value: 1 # reduce at most 1 pod per minute
periodSeconds: 60Practice An HPA that shrinks slowly
Write an HPA's spec section (starting with spec:): target apps/v1 Deployment api; minReplicas: 3, maxReplicas: 20; behavior.scaleDown.stabilizationWindowSeconds: 600.
Starter code
# buraya yazSample solution
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api
minReplicas: 3
maxReplicas: 20
behavior:
scaleDown:
stabilizationWindowSeconds: 600Expected output
horizontalpodautoscaler.autoscaling/api configured
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 If you see ScalingLimited True and TooManyReplicas, what does it mean?
- minReplicas is too high
- There are no metrics
- The load exceeds what maxReplicas can handle; the ceiling was hit Correct answer
- The HPA is broken
Explanation: The ceiling must be raised or pod efficiency improved.
2 Give a waiting window before scaling down.
scaleDown:
____: 300
scaleDown:
stabilizationWindowSeconds: 300
Explanation: During the window, the highest recommendation is used.
3 Match.
| Term | Meaning |
|---|---|
minReplicas |
Floor |
maxReplicas |
Ceiling |
stabilizationWindowSeconds |
Prevents flapping |
TooManyReplicas |
Hit the ceiling |