kubernetesprometheushorizontal-scaling

Can I use metrics from one application to automatically scale a different one?


I currently have a service running in my kubernetes cluster which exports my metrics to prometheus which is monitoring my cluster and services.

I want to use a metric from this service to automatically scale (hpa) a second service based on these metrics.

Is this possible to do?

Thanks in advance!


Solution

  • I've managed to make it work!

    You can choose the scale target in one parameter and under the metrics section choose the target of a different service.

    Example yaml

    kind: HorizontalPodAutoscaler
    apiVersion: autoscaling/v2beta1
    metadata:
      name: my-app-hpa
    spec:
      scaleTargetRef:
        apiVersion: apps/v1
        kind: Deployment
        name: my-app
      minReplicas: 1
      maxReplicas: 5
      metrics:
      - type: Object
        object:
          target:
            kind: Service
            name: app-that-generates-metrics
          metricName: my-metric
          targetValue: 10