Home > Software design >  Horizontal Pod Autoscaler (HPA) custom metrics with Prometheus Adapter (How are units defined?)
Horizontal Pod Autoscaler (HPA) custom metrics with Prometheus Adapter (How are units defined?)

Time:11-09

I'm testing out HPA with custom metrics from application and exposing to K8s using Prometheus-adapter.

My app exposes a "jobs_executing" custom metric that is a numerical valued guage (prometheus-client) in golang exposing number of jobs executed by the app (pod).

Now to cater this in hpa, here is how my HPA configuration looks like:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: myapp
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: myapp
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Pods
    pods:
      metric:
        name: jobs_executing
      target:
        type: AverageValue
        averageValue: 5

I want autoscaler to scale my pod when the average no. of jobs executed by overall pods equals "5". This works, but sometimes the HPA configuration shows values like this:

NAME             REFERENCE                           TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
my-autoscaler    Deployment/my-scaling-sample-app    7700m/5     1         10        10       38m

here targets show up as "7700m/5" even though the average no. of jobs executed overall were 7.7. This makes HPA just scale horizontally aggressively. I don't understand why it is putting "7700m" in the current target value"?

My question is, if there is a way to define a flaoting point here in HPA that doesn't confuse a normal integer with a 7700m (CPU unit?)

or what am I missing? Thank you

CodePudding user response:

From the docs:

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#appendix-quantities

All metrics in the HorizontalPodAutoscaler and metrics APIs are specified using a special whole-number notation known in Kubernetes as a quantity. For example, the quantity 10500m would be written as 10.5 in decimal notation. The metrics APIs will return whole numbers without a suffix when possible, and will generally return quantities in milli-units otherwise. This means you might see your metric value fluctuate between 1 and 1500m, or 1 and 1.5 when written in decimal notation.

So it does not seem like you are able to adjust the unit of measurement that the HPA uses, the generic Quantity.

  • Related