Monday, March 25, 2024

Using KEDA with Promethues scaler


 

In this post we will show a simple usage of KEDA with prometheus scaler to set the replicas number of a deployment.


KEDA is an event driven autoscaler, it wraps up the kubernetes horizontal pod autoscaler and simplify autoscaling while enabling scaler by a huge collection of scale metrics sources.


Deploy KEDA

Deploying KEDA is done by using helm chart:

helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm install keda kedacore/keda --namespace keda --create-namespace

Deploy a Scaledobject

A scaledobject is a configuration of the required auto scaling. We deploy the following scaledobject:


apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: my-scaledobject
namespace: default
spec:
minReplicaCount: 1
maxReplicaCount: 5
pollingInterval: 5
cooldownPeriod: 30
scaleTargetRef:
name: my-deployment
kind: Deployment
apiVersion: apps/v1
triggers:
- type: prometheus
metadata:
serverAddress: http://prometheus-service.default:80
threshold: '100'
query: sum (rate(handled_items[1m]))


We specify the min and max replicas, as well as the polling interval, and the cooldown internal.

The scaled object target is a deployment.

The metric source is prometheus, whose service address must be supplied. The scale is done using a promethues metric value. In this example, we set the threshold to 100, which means that above an average of 100 per pod, KEDA will scale up the replicas amount.





No comments:

Post a Comment