Exposing custom application metrics for autoscaling
You can use the resource to expose custom application metrics for the horizontal pod autoscaler.
Prerequisites
You have a custom Prometheus instance installed. In this example, it is presumed that Prometheus was installed in a user-defined
custom-prometheus
project.You have installed the OpenShift CLI (
oc
).
Procedure
Create a YAML file for your configuration. In this example, the file is called
deploy.yaml
.Add configuration details for creating the service account, roles, and role bindings for
prometheus-adapter
:Add configuration details for the custom metrics for
prometheus-adapter
:apiVersion: v1
kind: ConfigMap
metadata:
name: adapter-config
data:
config.yaml: |
rules:
- seriesQuery: 'http_requests_total{namespace!="",pod!=""}' (1)
resources:
overrides:
namespace: {resource: "namespace"}
pod: {resource: "pod"}
service: {resource: "service"}
name:
as: "${1}_per_second" (2)
---
Add configuration details for registering
prometheus-adapter
as an API service:-
$ oc get -n openshift-monitoring deploy/prometheus-adapter -o jsonpath="{..image}"
Add configuration details for deploying
prometheus-adapter
:Apply the configuration to the cluster:
$ oc apply -f deploy.yaml
Example output
Verify that the
prometheus-adapter
pod in your user-defined project is in aRunning
state. In this example the project iscustom-prometheus
:The metrics for the application are now exposed and they can be used to configure horizontal pod autoscaling.
Additional resources