Skip to content

Commit 5b7f161

Browse files
authored
Merge pull request #42918 from mburke5678/OSDOCS-3048-custom-autoscaling-keda
OSDOCS-3048 Tech preview of KEDA in 4.11
2 parents 3b232a4 + 344f812 commit 5b7f161

14 files changed

+1311
-2
lines changed

_topic_maps/_topic_map.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,8 @@ Topics:
19341934
Distros: openshift-enterprise,openshift-origin
19351935
- Name: Automatically scaling pods with the horizontal pod autoscaler
19361936
File: nodes-pods-autoscaling
1937+
- Name: Automatically scaling pods with the custom metrics autoscaler
1938+
File: nodes-pods-autoscaling-custom
19371939
- Name: Automatically adjust pod resource levels with the vertical pod autoscaler
19381940
File: nodes-pods-vertical-autoscaler
19391941
- Name: Providing sensitive data to pods
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
== Supported metrics
2+
3+
KEDA emits the following Kubernetes events:
4+
5+
.Metrics
6+
[cols="3a,5a,5a",options="header"]
7+
|===
8+
9+
|Metric |Description |API version
10+
11+
|ScaledObjectReady
12+
|Normal
13+
|On the first time a ScaledObject is ready, or if the previous ready condition status of the object was Unknown or False
14+
15+
|ScaledJobReady
16+
|Normal
17+
|On the first time a ScaledJob is ready, or if the previous ready condition status of the object was Unknown or False
18+
19+
|ScaledObjectCheckFailed
20+
|Warning
21+
|If the check validation for a ScaledObject fails
22+
23+
|ScaledJobCheckFailed
24+
|Warning
25+
|If the check validation for a ScaledJob fails
26+
27+
|ScaledObjectDeleted
28+
|Normal
29+
|When a ScaledObject is deleted and removed from KEDA watch
30+
31+
|ScaledJobDeleted
32+
|Normal
33+
|When a ScaledJob is deleted and removed from KEDA watch
34+
35+
|KEDAScalersStarted
36+
|Normal
37+
|When Scalers watch loop have started for a ScaledObject or ScaledJob
38+
39+
|KEDAScalersStopped
40+
|Normal
41+
|When Scalers watch loop have stopped for a ScaledObject or a ScaledJob
42+
43+
|KEDAScalerFailed
44+
|Warning
45+
|When a Scaler fails to create or check its event source
46+
47+
|KEDAScaleTargetActivated
48+
|Normal
49+
|When the scale target (Deployment, StatefulSet, etc) of a ScaledObject is scaled to 1
50+
51+
|KEDAScaleTargetDeactivated
52+
|Normal
53+
|When the scale target (Deployment, StatefulSet, etc) of a ScaledObject is scaled to 0
54+
55+
|KEDAScaleTargetActivationFailed
56+
|Warning
57+
|When KEDA fails to scale the scale target of a ScaledObject to 1
58+
59+
|KEDAScaleTargetDeactivationFailed
60+
|Warning
61+
|When KEDA fails to scale the scale target of a ScaledObject to 0
62+
63+
|KEDAJobsCreated
64+
|Normal
65+
|When KEDA creates jobs for a ScaledJob
66+
67+
|TriggerAuthenticationAdded
68+
|Normal
69+
|When a new TriggerAuthentication is added
70+
71+
|TriggerAuthenticationDeleted
72+
|Normal
73+
|When a TriggerAuthentication is deleted
74+
75+
|ClusterTriggerAuthenticationAdded
76+
|Normal
77+
|When a new ClusterTriggerAuthentication is added
78+
79+
|ClusterTriggerAuthenticationDeleted
80+
|Normal
81+
|When a ClusterTriggerAuthentication is deleted
82+
83+
|===
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * nodes/nodes-pods-autoscaling-custom.adoc
4+
5+
:_content-type: CONCEPT
6+
[id="nodes-pods-autoscaling-custom-about_{context}"]
7+
= Understanding the custom metrics autoscaler
8+
9+
The custom metrics autoscaler uses the Kubernetes-based Event Driven Autoscaler (KEDA) and is built on top of the {product-title} horizontal pod autoscaler (HPA).
10+
11+
The Custom Metrics Autoscaler Operator scales your pods up and down based on custom, external metrics from specific applications. Your other applications continue to use other scaling methods. You configure _triggers_, also known as scalers, which are the source of events and metrics that the custom metrics autoscaler uses to determine how to scale. The custom metrics autoscaler uses a metrics API to convert the external metrics to a form that {product-title} can use. The custom metrics autoscaler creates a horizontal pod autoscaler (HPA) that performs the actual scaling. The custom metrics autoscaler currently supports only the Prometheus trigger, which can use the installed {product-title} monitoring or an external Prometheus server as the metrics source.
12+
13+
To use the custom metrics autoscaler, you create a `ScaledObject` or `ScaledJob` object, which defines the scaling metadata. You specify the deployment or job to scale, the source of the metrics to scale on (trigger), and other parameters such as the minimum and maximum replica counts allowed.
14+
15+
[NOTE]
16+
====
17+
You can create only one scaled object or scaled job for each workload that you want to scale. Also, you cannot use a scaled object or scaled job and the horizontal pod autoscaler (HPA) on the same workload.
18+
====
19+
20+
////
21+
[NOTE]
22+
====
23+
You can create only one scaled object or scaled job for each workload that you want to scale. Also, you cannot use a scaled object or scaled job and the horizontal pod autoscaler (HPA) on the same workload. If you want to scale based on a custom trigger and CPU/Memory, you can create multiple triggers in the scaled object or scaled job.
24+
====
25+
////
26+
27+
You can verify that the autoscaling has taken place by reviewing the number of pods in your custom resource or by reviewing the Custom Metrics Autoscaler Operator logs for messages similar to the following:
28+
29+
[source,terminal]
30+
----
31+
Successfully set ScaleTarget replica count
32+
----
33+
34+
[source,terminal]
35+
----
36+
Successfully updated ScaleTarget
37+
----
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * nodes/nodes-pods-autoscaling-custom.adoc
4+
5+
:_content-type: CONCEPT
6+
[id="nodes-pods-autoscaling-custom-adding_{context}"]
7+
= Understanding how to add custom metrics autoscalers
8+
9+
To add a custom metrics autoscaler, create a `ScaledObject` custom resource for a deployment, stateful set, or custom resource. Create a `ScaledJob` custom resource for a job.
10+
11+
You can create only one scaled object or scaled job for each workload that you want to scale. Also, you cannot use a scaled object or scaled job and the horizontal pod autoscaler (HPA) on the same workload.
12+
13+
// If you want to scale based on a custom trigger and CPU/Memory, you can create multiple triggers in the scaled object or scaled job.
14+
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * nodes/nodes-pods-autoscaling-custom.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="nodes-pods-autoscaling-custom-creating-job_{context}"]
7+
= Adding a custom metrics autoscaler to a job
8+
9+
You can create a custom metrics autoscaler for any `Job` object.
10+
11+
.Prerequisites
12+
13+
* The Custom Metrics Autoscaler Operator must be installed.
14+
15+
.Procedure
16+
17+
. Create a YAML file similar to the following:
18+
+
19+
[source,yaml,options="nowrap"]
20+
----
21+
kind: ScaledJob
22+
apiVersion: keda.sh/v1alpha1
23+
metadata:
24+
name: scaledjob
25+
namespace: my-namespace
26+
spec:
27+
failedJobsHistoryLimit: 5
28+
jobTargetRef:
29+
activeDeadlineSeconds: 600 <1>
30+
backoffLimit: 6 <2>
31+
parallelism: 1 <3>
32+
completions: 1 <4>
33+
template: <5>
34+
metadata:
35+
name: pi
36+
spec:
37+
containers:
38+
- name: pi
39+
image: perl
40+
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
41+
maxReplicaCount: 100 <6>
42+
pollingInterval: 30 <7>
43+
successfulJobsHistoryLimit: 5 <8>
44+
failedJobsHistoryLimit: 5 <9>
45+
envSourceContainerName <10>
46+
rolloutStrategy: gradual <11>
47+
scalingStrategy: <12>
48+
strategy: "custom"
49+
customScalingQueueLengthDeduction: 1
50+
customScalingRunningJobPercentage: "0.5"
51+
pendingPodConditions:
52+
- "Ready"
53+
- "PodScheduled"
54+
- "AnyOtherCustomPodCondition"
55+
multipleScalersCalculation : "max"
56+
triggers:
57+
- type: prometheus <13>
58+
metadata:
59+
serverAddress: https://thanos-querier.openshift-monitoring.svc.cluster.local:9092
60+
namespace: kedatest
61+
metricName: http_requests_total
62+
threshold: '5'
63+
query: sum(rate(http_requests_total{job="test-app"}[1m]))
64+
authModes: "bearer"
65+
- authenticationRef: <14>
66+
name: prom-triggerauthentication
67+
metadata:
68+
name: prom-triggerauthentication
69+
type: object
70+
- authenticationRef: <15>
71+
name: prom-cluster-triggerauthentication
72+
metadata:
73+
name: prom-cluster-triggerauthentication
74+
type: object
75+
----
76+
<1> Specifies the maximum duration the job can run.
77+
<2> Specifies the number of retries for a job. The default is `6`.
78+
<3> Optional: Specifies how many pod replicas a job should run in parallel; defaults to `1`.
79+
* For non-parallel jobs, leave unset. When unset, the default is `1`.
80+
<4> Optional: Specifies how many successful pod completions are needed to mark a job completed.
81+
* For non-parallel jobs, leave unset. When unset, the default is `1`.
82+
* For parallel jobs with a fixed completion count, specify the number of completions.
83+
* For parallel jobs with a work queue, leave unset. When unset the default is the value of the `parallelism` parameter.
84+
<5> Specifies the template for the pod the controller creates.
85+
<6> Optional: Specifies the maximum number of replicas when scaling up. The default is `100`.
86+
<7> Optional: Specifies the interval in seconds to check each trigger on. The default is `30`.
87+
<8> Optional: Specifies the number of successful finished jobs should be kept. The default is `100`.
88+
<9> Optional: Specifies how many failed jobs should be kept. The default is `100`.
89+
<10> Optional: Specifies the name of the container in the target resource, from which the custom autoscaler gets environment variables holding secrets and so forth. The default is `.spec.template.spec.containers[0]`.
90+
<11> Optional: Specifies whether existing jobs are terminated whenever a scaled job is being updated:
91+
+
92+
--
93+
* `default`: The autoscaler terminates an existing job if its associated scaled job is updated. The autoscaler recreates the job with the latest specs.
94+
* `gradual`: The autoscaler does not terminate an existing job if its associated scaled job is updated. The autoscaler creates new jobs with the latest specs.
95+
--
96+
+
97+
<12> Optional: Specifies a scaling strategy: `default`, `custom`, or `accurate`. The default is `default`. For more information, see the link in the "Additional resources" section that follows.
98+
<13> Specifies the trigger to use as the basis for scaling, as described in the "Understanding the custom metrics autoscaler triggers" section.
99+
<14> Optional: Specifies a trigger authentication, as described in the "Creating a custom metrics autoscaler trigger authentication" section.
100+
<15> Optional: Specifies a cluster trigger authentication, as described in the "Creating a custom metrics autoscaler trigger authentication" section.
101+
+
102+
[NOTE]
103+
====
104+
It is not necessary to specify both a namespace trigger authentication and a cluster trigger authentication.
105+
====
106+
107+
. Create the custom metrics autoscaler:
108+
+
109+
[source,terminal]
110+
----
111+
$ oc create -f <file-name>.yaml
112+
----
113+
114+
.Verification
115+
116+
* View the command output to verify that the custom metrics autoscaler was created:
117+
+
118+
[source,terminal]
119+
----
120+
$ oc get scaledjob <scaled_job_name>
121+
----
122+
+
123+
.Example output
124+
[source,terminal]
125+
----
126+
NAME MAX TRIGGERS AUTHENTICATION READY ACTIVE AGE
127+
scaledjob 100 prometheus prom-triggerauthentication True True 8s
128+
----
129+
+
130+
Note the following fields in the output:
131+
+
132+
* `TRIGGERS`: Indicates the trigger, or scaler, that is being used.
133+
* `AUTHENTICATION`: Indicates the name of any trigger authentication being used.
134+
* `READY`: Indicates whether the scaled object is ready to start scaling:
135+
** If `True`, the scaled object is ready.
136+
** If `False`, the scaled object is not ready because of a problem in one or more of the objects you created.
137+
* `ACTIVE`: Indicates whether scaling is taking place:
138+
** If `True`, scaling is taking place.
139+
** If `False`, scaling is not taking place because there are no metrics or there is a problem in one or more of the objects you created.
140+
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * nodes/nodes-pods-autoscaling-custom.adoc
4+
5+
:_content-type: PROCEDURE
6+
[id="nodes-pods-autoscaling-custom-creating-trigger-auth_{context}"]
7+
= Using trigger authentications
8+
9+
You use trigger authentications and cluster trigger authentications by using a custom resource to create the authentication, then add a reference to a scaled object or scaled job.
10+
11+
.Prerequisites
12+
13+
* The Custom Metrics Autoscaler Operator must be installed.
14+
15+
* If you are using a secret, the `Secret` object must exist, for example:
16+
+
17+
.Example secret
18+
[source,yaml]
19+
----
20+
apiVersion: v1
21+
kind: Secret
22+
metadata:
23+
name: my-secret
24+
data:
25+
user-name: <base64_username>
26+
password: <base64_password>
27+
----
28+
29+
.Procedure
30+
31+
. Create the `TriggerAuthentication` or `ClusterTriggerAuthentication` object.
32+
33+
.. Create a YAML file that defines the object:
34+
+
35+
.Example trigger authentication with a secret
36+
[source,yaml]
37+
----
38+
kind: TriggerAuthentication
39+
apiVersion: keda.sh/v1alpha1
40+
metadata:
41+
name: prom-triggerauthentication
42+
namespace: my-namespace
43+
spec:
44+
secretTargetRef:
45+
- parameter: user-name
46+
name: my-secret
47+
key: USER_NAME
48+
- parameter: password
49+
name: my-secret
50+
key: PASSWORD
51+
----
52+
53+
.. Create the `TriggerAuthentication` object:
54+
+
55+
[source,terminal]
56+
----
57+
$ oc create -f <file-name>.yaml
58+
----
59+
60+
. Create or edit a `ScaledObject` YAML file:
61+
+
62+
.Example scaled object
63+
[source,yaml,options="nowrap"]
64+
----
65+
apiVersion: keda.sh/v1alpha1
66+
kind: ScaledObject
67+
metadata:
68+
name: scaledobject
69+
namespace: my-namespace
70+
spec:
71+
scaleTargetRef:
72+
name: example-deployment
73+
maxReplicaCount: 100
74+
minReplicaCount: 0
75+
pollingInterval: 30
76+
triggers:
77+
- authenticationRef:
78+
type: prometheus
79+
metadata:
80+
serverAddress: https://thanos-querier.openshift-monitoring.svc.cluster.local:9092
81+
namespace: kedatest # replace <NAMESPACE>
82+
metricName: http_requests_total
83+
threshold: '5'
84+
query: sum(rate(http_requests_total{job="test-app"}[1m]))
85+
authModes: "basic"
86+
- authenticationRef: <1>
87+
name: prom-triggerauthentication
88+
metadata:
89+
name: prom-triggerauthentication
90+
type: object
91+
- authenticationRef: <2>
92+
name: prom-cluster-triggerauthentication
93+
kind: ClusterTriggerAuthentication
94+
metadata:
95+
name: prom-cluster-triggerauthentication
96+
type: object
97+
----
98+
<1> Optional: Specify a trigger authentication.
99+
<2> Optional: Specify a cluster trigger authentication. You must include the `kind: ClusterTriggerAuthentication` parameter.
100+
+
101+
[NOTE]
102+
====
103+
It is not necessary to specify both a namespace trigger authentication and a cluster trigger authentication.
104+
====
105+
106+
. Create the object. For example:
107+
+
108+
[source,terminal]
109+
----
110+
$ oc apply -f <file-name>
111+
----
112+

0 commit comments

Comments
 (0)