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!
To start work with custom HPA
you need install on cluster some things:
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
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.