Container Talks
Published in

Container Talks

Autoscaling using KEDA based on Prometheus Metrics

Keda autoscaling using Prometheus metrics

In this blog, we are going to discuss how we can autoscale deployments on the basis of Prometheus metrics using KEDA.

What is Prometheus?

Prometheus is an open-source tool used for metrics-based monitoring and alerting. It is a very powerful tool for collecting and querying metric data. It collects data from application services and hosts and stores them in a time-series database. It offers a simple yet powerful data model and a query language (PromQL), and can provide detailed and actionable metrics using which we can analyse the performance of an application.

What is KEDA?

KEDA is a Kubernetes-based Event Driven Autoscaler. KEDA can be installed into any kubernetes cluster and can work alongside standard kubernetes components like the Horizontal Pod Autoscaler(HPA). When we install KEDA in any kubernetes cluster, two containers run. First one is keda-operator and second one is keda-operator-metrics-apiserver. Here, Role of keda-operator is to scale Deployments, Statefulsets or Rollouts from zero or to zero on no events. KEDA acts as a kubernetes metrics server that exposes rich event data like queue length or stream lag to the HPA to drive scale out.The metric serving is the primary role of the second container i.e. keda-operator-metrics-apiserver.

Installing KEDA (Using Helm)

  1. Add helm repo & update
helm repo add kedacore
helm repo update

2. Install keda helm chart

helm install keda kedacore/keda --version 1.4.2 --create-namespace --namespace keda

Now let’s take an example and see how autoscaling yaml looks like.

kind: ScaledObject
name: prometheus-scaledobject
namespace: demo3
kind: Rollout
name: keda-test-demo3
- type: prometheus
serverAddress: http://<prometheus-host>:9090
metricName: http_request_total
query: envoy_cluster_upstream_rq{appId="300", cluster_name="300-0", container="envoy", namespace="demo3", response_code="200" }
threshold: "50"
idleReplicaCount: 0
minReplicaCount: 1
maxReplicaCount: 10

In .spec.triggers section, we provide the informations that KEDA uses to trigger the autoscaling. Here are some parameters which can be used for autoscaling.

keda autoscaling based on prometheus metrics



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Devtron Labs

Devtron Labs

Devtron is an open source no-code solution for Kubernetes deployments.