I would like to know if there is a way to override the way Kubernetes does the HPA calculation.
I’m talking about this formula in the official doc :
desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]
This formula doesn’t suit our needs. What we would like would be some sort of proportional number of replicas.
Our metric is custom and based on the number of jobs (units of work) planned to be executed.
So for example, we would like to be able do have 1 pod for 300 jobs planned.
If there are 1100 jobs planned, that would mean 4 pods.
The way it works by default is like a value that creates pods to the limit whan the metric is above a certain value, but not proportional.
I didn’t see anything like this in the doc, so i don’t think it’s possible, but maybe i’m wrong ?
Thanks !
1
As I know there is no way to change this formula in Kubernetes HPA. But I think you can create your custom metric and use it in HPA. HPA uses CPU and memory metrics, but custom metrics provide a more nuanced approach to scaling by reflecting specific application behaviors or demands. For example you can specify the metric to control one pod for every 300 jobs:
metrics:
- type: Pods
pods:
metric:
name: custom_metric_calculating_jobs_per_pod
target:
type: AverageValue
averageValue: "1"
Or you can use KEDA (Kubernetes Event-driven autoscaling) for this purposes