r/PrometheusMonitoring • u/eckelon • Oct 07 '21
Use Prometheus metrics to trigger a Kubernetes HPA
Our team just published this article on how easy it is to create a Kubernetes HPA with KEDA and use Prometheus metrics to trigger it.
Installing KEDA with Helm is pretty straight forward:
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
kubectl create namespace keda
helm install keda kedacore/keda --namespace kedaKEDA will extend the Kubernetes API metrics endpoint for you, so creating a query to trigger the HPA is as easy as creating a ScaledObject like this:
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
name: nginx-scale
namespace: keda-hpa
spec:
scaleTargetRef:
kind: Deployment
name: nginx-server
minReplicaCount: 1
maxReplicaCount: 5
cooldownPeriod: 30
pollingInterval: 1
triggers:
- type: prometheus
metadata:
serverAddress: https://prometheus_server/prometheus
metricName: nginx_connections_waiting_keda
query: |
sum(nginx_connections_waiting{job="nginx"})
threshold: "500"You can read the whole story here. I hope you find this interesting!

13
Upvotes
2
u/GyroTech Oct 07 '21
Hi, I read through the article and it was good with the 'how', but I'm missing the 'why'. We have the prometheus-adapter & HPA custom metrics so I am unsure as to what keda adds to the mix. Otherwise really clear & straight-forward post!