kuberneteshpa

How to change tolerance in Kubernetes HPA?


In Kubernetes docs https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details it is said that:

For example, if the current metric value is 200m, and the desired value is 100m, the number of replicas will be doubled, since 200.0 / 100.0 == 2.0 If the current value is instead 50m, you'll halve the number of replicas, since 50.0 / 100.0 == 0.5. The control plane skips any scaling action if the ratio is sufficiently close to 1.0 (within a globally-configurable tolerance, 0.1 by default).

But there is no information how to change this tolerance in yaml hpa config. Below is my hpa config

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: my-app-hpa
  namespace: my-app
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: my-app
  minReplicas: 1
  maxReplicas: 6
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70

How can I modify value of tolerance?


Solution

  • The tolerance value for the horizontal pod autoscaler (HPA) in Kubernetes is a global configuration setting and it's not set on the individual HPA object. It is set on the controller manager that runs on the Kubernetes control plane. You can change the tolerance value by modifying the configuration file of the controller manager and then restarting the controller manager.