Skip to content

Commit 0455f7e

Browse files
committed
Need new section to address horizontal-pod-autoscaler-downscale-stabilization parameter
1 parent 71fb651 commit 0455f7e

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

modules/nodes-pods-autoscaling-creating-memory.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ spec:
9595
target:
9696
type: AverageValue <10>
9797
averageValue: 500Mi <11>
98+
behavior: <12>
99+
scaleDown:
100+
stabilizationWindowSeconds: 300
101+
policies:
102+
- type: Pods
103+
value: 4
104+
periodSeconds: 60
105+
- type: Percent
106+
value: 10
107+
periodSeconds: 60
108+
selectPolicy: Max
98109
----
99110
<1> Use the `autoscaling/v2beta2` API.
100111
<2> Specify a name for this horizontal pod autoscaler object.
@@ -109,6 +120,7 @@ spec:
109120
<9> Specify `memory` for memory utilization.
110121
<10> Set the type to `AverageValue`.
111122
<11> Specify `averageValue` and a specific memory value.
123+
<12> Optional: Specify a scaling policy to control the rate of scaling up or down.
112124

113125
** To scale for a percentage, create a `HorizontalPodAutoscaler` object similar to the following:
114126
+
@@ -133,6 +145,17 @@ spec:
133145
target:
134146
type: Utilization <10>
135147
averageUtilization: 50 <11>
148+
behavior: <12>
149+
scaleUp:
150+
stabilizationWindowSeconds: 180
151+
policies:
152+
- type: Pods
153+
value: 6
154+
periodSeconds: 120
155+
- type: Percent
156+
value: 10
157+
periodSeconds: 120
158+
selectPolicy: Max
136159
----
137160
<1> Use the `autoscaling/v2beta2` API.
138161
<2> Specify a name for this horizontal pod autoscaler object.
@@ -148,6 +171,7 @@ spec:
148171
<10> Set to `Utilization`.
149172
<11> Specify `averageUtilization` and a target average memory utilization over all the Pods,
150173
represented as a percent of requested memory. The target pods must have memory requests configured.
174+
<12> Optional: Specify a scaling policy to control the rate of scaling up or down.
151175

152176
. Create the horizontal pod autoscaler:
153177
+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * nodes/nodes-pods-autoscaling.adoc
4+
5+
[id="nodes-pods-autoscaling-policies_{context}"]
6+
= Scaling policies
7+
8+
The `autoscaling/v2beta2` API allows you to add _scaling policies_ to a horizontal pod autoscaler. A scaling policy controls how the {product-title} horizontal pod autoscaler (HPA) scales pods. Scaling policies allow you to restrict the rate that HPAs scale pods up or down by setting a specific number or specific percentage to scale in a specified period of time. You can also define a _stabilization window_, which uses previously computed desired states to control scaling if the metrics are fluctuating. You can create multiple policies for the same scaling direction, and determine which policy is used, based on the amount of change. You can also restrict the scaling by timed iterations. The HPA scales pods during an iteration, then performs scaling, as needed, in further iterations.
9+
10+
.Sample HPA object with a scaling policy
11+
[source, yaml]
12+
----
13+
apiVersion: autoscaling/v2beta2
14+
kind: HorizontalPodAutoscaler
15+
metadata:
16+
name: hpa-resource-metrics-memory
17+
namespace: default
18+
spec:
19+
behavior:
20+
scaleDown: <1>
21+
policies: <2>
22+
- type: Pods <3>
23+
value: 4 <4>
24+
periodSeconds: 60 <5>
25+
- type: Percent
26+
value: 10 <6>
27+
periodSeconds: 60
28+
selectPolicy: Min <7>
29+
stabilizationWindowSeconds: 300 <8>
30+
scaleUp: <9>
31+
policies:
32+
- type: Pods
33+
value: 5 <10>
34+
periodSeconds: 70
35+
- type: Percent
36+
value: 12 <11>
37+
periodSeconds: 80
38+
selectPolicy: Max
39+
stabilizationWindowSeconds: 0
40+
...
41+
----
42+
<1> Specifies the direction for the scaling policy, either `scaleDown` or `scaleUp`. This example creates a policy for scaling down.
43+
<2> Defines the scaling policy.
44+
<3> Determines if the policy scales by a specific number of pods or a percentage of pods during each iteration. The default value is `pods`.
45+
<4> Determines the amount of scaling, either the number of pods or percentage of pods, during each iteration. There is no default value for scaling down by number of pods.
46+
<5> Determines the length of a scaling iteration. The default value is `15` seconds.
47+
<6> The default value for scaling down by percentage is 100%.
48+
<7> Determines which policy to use first, if multiple policies are defined. Specify `Max` to use the policy that allows the highest amount of change, `Min` to use the policy that allows the lowest amount of change, or `Disabled` to prevent the HPA from scaling in that policy direction. The default value is `Max`.
49+
<8> Determines the time period the HPA should look back at desired states. The default value is `0`.
50+
<9> This example creates a policy for scaling up.
51+
<10> The amount of scaling up by the number of pods. The default value for scaling up the number of pods is 4%.
52+
<11> The amount of scaling up by the percentage of pods. The default value for scaling up by percentage is 100%.
53+
54+
.Example policy for scaling down
55+
[source,yaml]
56+
----
57+
apiVersion: autoscaling/v2beta2
58+
kind: HorizontalPodAutoscaler
59+
metadata:
60+
name: hpa-resource-metrics-memory
61+
namespace: default
62+
spec:
63+
...
64+
minReplicas: 20
65+
...
66+
behavior:
67+
scaleDown:
68+
stabilizationWindowSeconds: 300
69+
policies:
70+
- type: Pods
71+
value: 4
72+
periodSeconds: 30
73+
- type: Percent
74+
value: 10
75+
periodSeconds: 60
76+
selectPolicy: Max
77+
scaleUp:
78+
selectPolicy: Disabled
79+
----
80+
81+
In this example, when the number of pods is greater than 40, the percent-based policy is used for scaling down, as that policy results in a larger change, as required by the `selectPolicy`.
82+
83+
If there are 80 pod replicas, in the first iteration the HPA reduces the pods by 8, which is 10% of the 80 pods (based on the `type: Percent` and `value: 10` parameters), over one minute (`periodSeconds: 60`). For the next iteration, the number of pods is 72. The HPA calculates that 10% of the remaining pods is 7.2, which it rounds up to 8 and scales down 8 pods. On each subsequent iteration, the number of pods to be scaled is re-calculated based on the number of remaining pods. When the number of pods falls below 40, the pods-based policy is applied, because the pod-based number is greater than the percent-based number. The HPA reduces 4 pods at a time (`type: Pods` and `value: 4`), over 30 seconds (`periodSeconds: 30`), until there are 20 replicas remaining (`minReplicas`).
84+
85+
The `selectPolicy: Disabled` parameter prevents the HPA from scaling up the pods. You can manually scale up by adjusting the number of replicas in the replica set or deployment set, if needed.
86+
87+
If set, you can view the scaling policy by using the `oc edit` command:
88+
89+
[source,terminal]
90+
----
91+
$ oc edit hpa hpa-resource-metrics-memory
92+
----
93+
94+
.Example output
95+
[source,terminal]
96+
----
97+
apiVersion: autoscaling/v1
98+
kind: HorizontalPodAutoscaler
99+
metadata:
100+
annotations:
101+
autoscaling.alpha.kubernetes.io/behavior:\
102+
'{"ScaleUp":{"StabilizationWindowSeconds":0,"SelectPolicy":"Max","Policies":[{"Type":"Pods","Value":4,"PeriodSeconds":15},{"Type":"Percent","Value":100,"PeriodSeconds":15}]},\
103+
"ScaleDown":{"StabilizationWindowSeconds":300,"SelectPolicy":"Min","Policies":[{"Type":"Pods","Value":4,"PeriodSeconds":60},{"Type":"Percent","Value":10,"PeriodSeconds":60}]}}'
104+
...
105+
----
106+

nodes/pods/nodes-pods-autoscaling.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ configuration.
1919

2020
include::modules/nodes-pods-autoscaling-about.adoc[leveloffset=+1]
2121

22+
include::modules/nodes-pods-autoscaling-policies.adoc[leveloffset=+2]
23+
2224
include::modules/nodes-pods-autoscaling-creating-cpu.adoc[leveloffset=+1]
2325

2426
include::modules/nodes-pods-autoscaling-creating-memory.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)