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

10/8/2018

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!

-- Yonah Dissen
horizontal-scaling
kubernetes
prometheus

3 Answers

10/8/2018

To start work with custom HPA you need install on cluster some things:

  1. Enable Kubernetes Aggregator Layer
  2. Start using metrics-server (instead heapster);
-- Arslanbekov
Source: StackOverflow

10/30/2018

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
-- Yonah Dissen
Source: StackOverflow

10/8/2018

I never tested what you want to do, but here you have a tutorial on how to scale a pod with custom metrics: https://docs.bitnami.com/kubernetes/how-to/configure-autoscaling-custom-metrics/

You may have some tweeking to do to use a metric from a pod to scale another, but I hope it helps.

-- night-gold
Source: StackOverflow