Autoscaling applications with custom metrics
In order for you to use custom metrics, the following must be fulfilled:
- Your application needs to be instrumented to produce metrics.
- These metrics need to be exposed through the
custom.metrics.k8s.io
endpoint.
The application developer or dev team is responsible for point 1, and we will install and use Prometheus and the Prometheus adapter to satisfy point 2. The following diagram illustrates the high-level flow of this solution.
Figure 18.8 – HPA custom metrics high-level flow
Let’s look at the flow in brief.
- The Prometheus server installed in your cluster will “scrape” custom metrics from your pods.
- HPA will do the following:
- Read metrics from the
custom.metrics.k8s.io
custom endpoint, hosted on the Prometheus adapter. - The Prometheus adapter will pull data from the Prometheus server.
- Read metrics from the
- HPA assesses these metrics against the desired state of the autoscaling...