If you configure an application to export metrics, you can set up Horizontal Pod Autoscaling (HPA) based on these metrics.
-
Create a YAML file for your configuration. In this example, it is called
deploy.yaml
. -
Add configuration for deploying the horizontal pod autoscaler for the application. This example configures and deploys HPA based on the application
http_requests_per_second
metric for the sample application configured in the "Application monitoring" section:apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: name: example-app-scaler namespace: default spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: example-app (1) minReplicas: 3 (2) maxReplicas: 10 (3) metrics: - type: Pods pods: metricName: http_requests_per_second (4) targetAverageValue: 10 (5)
-
name
specifies the application. -
minReplicas
specifies the minimum number of replicas for the HPA to maintain for the application. -
maxReplicas
specifies the maximum number of replicas for the HPA to maintain for the application. -
metricName
specifies the metric upon which HPA is based. Here, specify the metric you previously exposed for your application. -
targetAverageValue
specifies the value of the metric for the HPA to try to maintain by increasing or decreasing the number of replicas.
-
-
Apply the configuration file to the cluster:
$ oc apply -f deploy.yaml