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

    1. Create a YAML file for your configuration. In this example, the file is called deploy.yaml.

    2. Add configuration details for creating the service account, roles, and role bindings for prometheus-adapter:

    3. Add configuration details for the custom metrics for prometheus-adapter:

      1. apiVersion: v1
      2. kind: ConfigMap
      3. metadata:
      4. name: adapter-config
      5. data:
      6. config.yaml: |
      7. rules:
      8. - seriesQuery: 'http_requests_total{namespace!="",pod!=""}' (1)
      9. resources:
      10. overrides:
      11. namespace: {resource: "namespace"}
      12. pod: {resource: "pod"}
      13. service: {resource: "service"}
      14. name:
      15. as: "${1}_per_second" (2)
      16. ---
    4. Add configuration details for registering prometheus-adapter as an API service:

      1. $ oc get -n openshift-monitoring deploy/prometheus-adapter -o jsonpath="{..image}"
    5. Add configuration details for deploying prometheus-adapter:

    6. Apply the configuration to the cluster:

      1. $ oc apply -f deploy.yaml

      Example output

    7. Verify that the prometheus-adapter pod in your user-defined project is in a Running state. In this example the project is custom-prometheus:

    8. The metrics for the application are now exposed and they can be used to configure horizontal pod autoscaling.

    Additional resources

    Next steps