问题
I had been trying to implement Kubernetes HPA using Metrics from Kafka-exporter. Hpa supports Prometheus, so we tried writing the metrics to prometheus instance. From there, we are unclear on the steps to do. Is there an article where it will explain in details ?
I followed https://medium.com/google-cloud/kubernetes-hpa-autoscaling-with-kafka-metrics-88a671497f07
for same in GCP and we used stack driver, and the implementation worked like a charm. But, we are struggling in on-premise setup, as stack driver needs to be replaced by Prometheus
回答1:
In order to scale based on custom metrics, Kubernetes needs to query an API for metrics to check for those metrics. That API needs to implement the custom metrics interface.
So for Prometheus, you need to setup an API that exposes Prometheus metrics through the custom metrics API. Luckily, there already is an adapter.
回答2:
When I implemented Kubernetes HPA using Metrics from Kafka-exporter I had a few setbacks which I solved doing the following:
- I deployed the kafka-exporter container as a sidecar to the pods I wanted to scale. I found that the HPA scales the pod it gets the metrics from.
I used annotations to make Prometheus scrape the metrics from the pods with exporter.
Then I verified that the kafka-exporter metrics are getting to Prometheus. If it's not there you can't advance further.
- I deployed prometheus adapter using its helm chart. The adapter will "translate" Prometheus's metrics into custom Metrics Api, which will make it visible to HPA.
- I made sure that the metrics are visible in k8s by executing
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1
from one of the master nodes. - I created an hpa with the matching metric name.
Here is a complete guide explaining how to implement Kubernetes HPA using Metrics from Kafka-exporter
Please comment if you have more questions
来源:https://stackoverflow.com/questions/57361180/hpa-using-kafka-exporter-in-on-premise-kubernetes-cluster