Exploring Prometheus Adapter
Explore how to install the Prometheus Adapter using Helm to extend Kubernetes' HorizontalPodAutoscaler with custom metrics. Understand querying the Custom Metrics API, filtering relevant metrics, and configuring the adapter to optimize autoscaling based on application-specific data from Prometheus.
We'll cover the following...
Given that we want to extend the metrics available through the Metrics API and that Kubernetes allows us to do so through its Custom Metrics API, one option to accomplish our goals could be to create our own adapter. Depending on the application (DB) where we store metrics, that might be a good option. But, given that it is pointless to reinvent the wheel, our first step should be to search for a solution. If someone already created an adapter that suits our needs, it would make sense to adopt it instead of creating a new one by ourselves. Even if we do choose something that provides only part of the features we’re looking for, it’s easier to build on top of it (and contribute back to the project) than to start from scratch.
Prometheus Adapter
Given that our metrics are stored in Prometheus, we need a metrics adapter that will be capable of fetching data from it. Since Prometheus is very popular and adopted by the community, there is already a project waiting for us to use. It’s called Kubernetes Custom Metrics Adapter for Prometheus. It is an implementation of the Kubernetes Custom Metrics API that uses Prometheus as the data source.
Since we adopted Helm for all our installations, we’ll use it to install the adapter.
helm install prometheus-adapter \
stable/prometheus-adapter \
--version 1.4.0 \
--namespace metrics \
--set image.tag=v0.5.0 \
--set metricsRelistInterval=90s \
--set prometheus.url=http://prometheus-server.metrics.svc \
--set prometheus.port=80
kubectl -n metrics \
rollout status \
deployment prometheus-adapter
We installed the prometheus-adapter Helm Chart from the stable repository. The resources were created in the metrics Namespace, and the image.tag is set to v0.3.0.
We changed metricsRelistInterval from the default value of 30s to 90s. That is the interval the adapter will use to fetch metrics from Prometheus. Since our Prometheus setup is fetching metrics from its targets every sixty seconds, we had to set the adapter’s interval to ...