Skip to content

Commit 2044671

Browse files
authored
Merge pull request #23557 from mburke5678/BZ-1851187
Need new section to address horizontal-pod-autoscaler-downscale-stabilization parameter
2 parents 240fca5 + 0455f7e commit 2044671

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
@@ -83,6 +83,17 @@ spec:
8383
target:
8484
type: AverageValue <10>
8585
averageValue: 500Mi <11>
86+
behavior: <12>
87+
scaleDown:
88+
stabilizationWindowSeconds: 300
89+
policies:
90+
- type: Pods
91+
value: 4
92+
periodSeconds: 60
93+
- type: Percent
94+
value: 10
95+
periodSeconds: 60
96+
selectPolicy: Max
8697
----
8798
<1> Use the `autoscaling/v2beta2` API.
8899
<2> Specify a name for this horizontal pod autoscaler object.
@@ -97,6 +108,7 @@ spec:
97108
<9> Specify `memory` for memory utilization.
98109
<10> Set the type to `AverageValue`.
99110
<11> Specify `averageValue` and a specific memory value.
111+
<12> Optional: Specify a scaling policy to control the rate of scaling up or down.
100112

101113
** To scale for a percentage, create a `HorizontalPodAutoscaler` object similar to the following:
102114
+
@@ -122,6 +134,17 @@ spec:
122134
target:
123135
type: Utilization <10>
124136
averageUtilization: 50 <11>
137+
behavior: <12>
138+
scaleUp:
139+
stabilizationWindowSeconds: 180
140+
policies:
141+
- type: Pods
142+
value: 6
143+
periodSeconds: 120
144+
- type: Percent
145+
value: 10
146+
periodSeconds: 120
147+
selectPolicy: Max
125148
----
126149
<1> Use the `autoscaling/v2beta2` API.
127150
<2> Specify a name for this horizontal pod autoscaler object.
@@ -137,6 +160,7 @@ spec:
137160
<10> Set to `Utilization`.
138161
<11> Specify `averageUtilization` and a target average memory utilization over all the pods,
139162
represented as a percent of requested memory. The target pods must have memory requests configured.
163+
<12> Optional: Specify a scaling policy to control the rate of scaling up or down.
140164

141165
. Create the horizontal pod autoscaler:
142166
+
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)