r/kubernetes•
RRethy

Is the documentation wrong for HPA AverageValue External metrics?

HPA Docs

In the docs it says for external metrics with type AverageValue, the HPA will get all pods in the scale target, then filter some of them out based on having a termination timestamp or if it wasn't made Ready within the past 30 seconds.

However, if I look at the source code I see something different.

  1. computeReplicasForMetric is called
  2. Which takes this branch
  3. computeStatusForExternalMetric is called
  4. Which takes this branch
  5. GetExternalPerPodMetricReplicas is called
  6. Which calculates a replica count
  7. Which uses the status.replicas from the Scale sub-resource on the Deployment

This becomes an issue when using Keda's fallback mechanism (or any static metric) which just sets the target to 1 and value to fallback.replicas so the external metric with type AverageValue can scale the workload to that value. But during a deployment, the available replicas according to the scale sub-resource can be quite a bit higher (e.g. maxSurge 100%, maxUnavailable 0%) which could theoretically cause the HPA to scale down the workload.

With that being said, I tried manually testing this and haven't been able to get it to scale down. Any help would be appreciated, not sure if I should open an issue to ask the K8s team.

Posted Feb 12, 2024, 7:17 PM UTC

20

No comments yet

Nobody commented on this post, or the comments weren't captured.