Reputation: 37106
I am reading following documentation. I want to understand how to use behavior
One or more scaling policies can be specified in the behavior section of the spec. When multiple policies are specified the policy which allows the highest amount of change is the policy which is selected by default. The following example shows this behavior while scaling down:
behavior:
scaleDown:
policies:
- type: Pods
value: 4
periodSeconds: 60
- type: Percent
value: 10
periodSeconds: 60
When the number of pods is more than 40 the second policy will be used for scaling down. For instance if there are 80 replicas and the target has to be scaled down to 10 replicas then during the first step 8 replicas will be reduced. In the next iteration when the number of replicas is 72, 10% of the pods is 7.2 but the number is rounded up to 8. On each loop of the autoscaler controller the number of pods to be change is re-calculated based on the number of current replicas. When the number of replicas falls below 40 the first policy(Pods) is applied and 4 replicas will be reduced at a time. ...
I understood that when autoscaler decides to scale down - it reduces amount of replics by 10% portions because of rule:
- type: Percent
value: 10
periodSeconds: 60
but I can't understand the meaning of the first rule. Could you please clarify ?
How is it possible to have 80 nodes when we have such config? How is it possible to have 80 nodes if kubernetes starts to to reduce amount of nodes each time when we have > 40 nodes
Upvotes: 1
Views: 512
Reputation: 1948
How is it possible to have 80 nodes when we have such config?
The example (in documentation you referring to) says about 80 Pods, but that is just a random number to illustrate a particular example.
How is it possible to have 80 nodes if kubernetes starts to to reduce amount of nodes each time when we have > 40 nodes
Not each time. It starts reducing amount of Pods only if/when Autoscaler decides to scale down.
I understood that when autoscaler decides to scale down - it reduces amount of replics by 10% portions
You are right that the documentation describes the case when there were 80 Pods and due to lack of load it is time to "deflate" cluster to lower amount of Pods.
but I can't understand the meaning of the first rule. Could you please clarify ?
Lets go through it one more time.
behavior:
scaleDown:
policies:
- type: Pods
value: 4
periodSeconds: 60
- type: Percent
value: 10
periodSeconds: 60
You can see two policies here. Namely Pods
and Percent
. When multiple policies are specified the policy which allows the highest amount of change is the policy which is selected by default.
That is why in case there are 80 pods and system has to downscale to let's say 10, it checks how many pods it can shutdown with each policy.
Pods
allow to shutdown only 4 pods at a time, while Percent
80Pods*10Percent=8Pods. The Percent
wins, 8 Pods shut down, 72 Pods left and process starts again.
This time Percent
allows to shutdown 72*0.1=7.2 Pods. Still more than 4. The value is rounded up to 8. That is why, again 10% of alive Pods are shut down. 72-8=64Pods left.
On each loop of the autoscaler controller the number of pods to be change is re-calculated based on the number of current replicas.
So the progress would be like 80 (-8) --> 72 (-8) --> 64 (-7) --> 57 (-6) --> 51 (-6) --> 45 (-5) --> 40
When the number of replicas falls below 40 the first policy Pods
is applied and 4 replicas will be reduced at a time.
With 40 pods left both Pods
and Percent
are about shutting down 4 Pods.
36 Pods left, 10% is 3.6 Pods (before rounding up) which is definitely less than 4 Pods by first rule. The Pods
wins, 4 Pods shut down.
The progress would be like 36 (-4) --> 32 (-4) --> 28... and so on.
Hope that helps! :)
Upvotes: 3