Lesson 2 · Unit 04
Autoscaling
The autoscaler's formula on real numbers, and why requests must be set.
What you practise
- The horizontal autoscaler's formula worked on numbers, scaling nodes in outline, why requests must be set
Try a question from this lesson
Pick one
Four Pods each run at 90% of the CPU they asked for. You want them near 60%. If the same work is spread evenly, how many Pods bring the average down to 60%?
Hint
Total up the work first, then divide it by what one Pod should carry.
Correct answer
6
Why
The work is 4 times 90, or 360 units. At 60 units per Pod that takes 6 Pods. This proportion, the current count times current load over target load, is the whole idea of the autoscaler.
The ideas
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
HorizontalPodAutoscaler
A HorizontalPodAutoscaler is a controller that changes replicas for you. At a regular interval it compares a measured value with your target and computes:
desired = ceil(current × measured / target)
It rounds up, stays between minReplicas and maxReplicas, and does nothing when the ratio is within 10% of 1, so small wobbles cause no churn.
The object's apiVersion is autoscaling/v2. Its spec:
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60Concept
Utilization is measured against requests
CPU utilization, for the autoscaler, is not a share of the machine. It is a Pod's real CPU use as a percentage of its CPU request, averaged over the Pods.
A Pod requesting 200m and using 300m is at 150%.
So requests must be set. If a container has no CPU request, utilization cannot be computed, and the autoscaler takes no action on that metric. The scheduler needs the same number to place the Pod.
resources:
requests:
cpu: 200m
limits:
cpu: 500m10 more exercises in the app
- 3× type the answer
- 3× multiple choice
- 2× true or false
- 1× order the lines
- 1× match the pairs
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.