Skip to content

Commit c05161b

Browse files
pPrecelkwiatekusgrego952
authored
Keda prometheus scaler tutorial (kyma-project#15305)
* improve docs * improve docs v2 * Apply suggestions from code review Co-authored-by: Krzysztof Kwiatosz <[email protected]> * Fix docs * Update svls-15-use-external-scalers.md * Apply suggestions from code review Co-authored-by: Grzegorz Karaluch <[email protected]> Co-authored-by: Krzysztof Kwiatosz <[email protected]> Co-authored-by: Grzegorz Karaluch <[email protected]>
1 parent ef178ba commit c05161b

File tree

1 file changed

+75
-4
lines changed

1 file changed

+75
-4
lines changed

docs/03-tutorials/00-serverless/svls-15-use-external-scalers.md

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Follow these steps:
6666

6767
</details>
6868
<details>
69-
<summary label="keda">
70-
Keda
69+
<summary label="keda-cpu">
70+
Keda CPU
7171
</summary>
7272

7373
1. Install [Keda](https://keda.sh/docs/2.8/deploy/) if it is not present on your cluster.
@@ -118,9 +118,9 @@ Follow these steps:
118118
EOF
119119
```
120120

121-
>**NOTE:** in this tutorial we use the `cpu` trigger because of its simple configuration. If you want to use another trigger check the official [list of supported triggers](https://keda.sh/docs/2.8/scalers/).
121+
>**NOTE:** This tutorial uses the `cpu` trigger because of its simple configuration. If you want to use another trigger check the official [list of supported triggers](https://keda.sh/docs/2.8/scalers/).
122122

123-
4. After a few seconds ScaledObject should be up to date and contain information about actual replicas:
123+
4. After a few seconds ScaledObject should be up to date and contain information about the actual replicas:
124124

125125
```bash
126126
kubectl get scaledobject scaled-function
@@ -133,5 +133,76 @@ Follow these steps:
133133
scaled-function serverless.kyma-project.io/v1alpha2.Function scaled-function 5 10 cpu True True Unknown 4m15s
134134
```
135135

136+
</details>
137+
<details>
138+
<summary label="keda-prometheus">
139+
Keda Prometheus
140+
</summary>
141+
142+
1. Install [Keda](https://keda.sh/docs/2.8/deploy/) if it is not present on your cluster.
143+
144+
2. Create your Function with the `replicas` value set to 1, to prevent the internal Serverless HPA creation:
145+
146+
```yaml
147+
cat <<EOF | kubectl apply -f -
148+
apiVersion: serverless.kyma-project.io/v1alpha2
149+
kind: Function
150+
metadata:
151+
name: scaled-function
152+
spec:
153+
runtime: nodejs14
154+
replicas: 1
155+
source:
156+
inline:
157+
dependencies: ""
158+
source: |
159+
module.exports = {
160+
main: function(event, context) {
161+
return 'Hello World!'
162+
}
163+
}
164+
EOF
165+
```
166+
167+
3. Create the ScaledObject resource based on the `istio_requests_total` metric, exposed by the Istio:
168+
169+
```yaml
170+
cat <<EOF | kubectl apply -f -
171+
apiVersion: keda.sh/v1alpha1
172+
kind: ScaledObject
173+
metadata:
174+
name: scaled-function
175+
spec:
176+
scaleTargetRef:
177+
apiVersion: serverless.kyma-project.io/v1alpha2
178+
kind: Function
179+
name: scaled-function
180+
minReplicaCount: 1 # You can go with 0 ( scaling to zero ) in case your function is fed from messaging queue that would buffer unhandled requests or if you are fine with function downtime at cold start periods
181+
maxReplicaCount: 5
182+
triggers:
183+
- type: prometheus
184+
metadata:
185+
serverAddress: http://prometheus-operated.kyma-system.svc.cluster.local:9090
186+
metricName: istio_requests_total
187+
query: round(sum(irate(istio_requests_total{reporter=~"source",destination_service=~"scaled-function.default.svc.cluster.local"}[2m])), 0.001)
188+
threshold: '6.5'
189+
EOF
190+
```
191+
192+
>**NOTE:** This tutorial uses the `prometheus` trigger because of its simple configuration. If you want to use another trigger check the official [list of supported triggers](https://keda.sh/docs/2.8/scalers/).
193+
194+
4. After a few seconds ScaledObject should be up to date and contain information about the actual replicas:
195+
196+
```bash
197+
kubectl get scaledobject scaled-function
198+
```
199+
200+
You should get a result similar to this example:
201+
202+
```bash
203+
NAME SCALETARGETKIND SCALETARGETNAME MIN MAX TRIGGERS AUTHENTICATION READY ACTIVE FALLBACK AGE
204+
scaled-function serverless.kyma-project.io/v1alpha2.Function scaled-function 1 5 prometheus True True Unknown 4m15s
205+
```
206+
136207
</details>
137208
</div>

0 commit comments

Comments
 (0)