<p>I have a web application hosted in EKS and there is a matrix in place for CPU utilization for scaling the pods horizontally.</p>
<p>If the current number of pods is 10, and I increase the load (increasing requests per minute) then the desired number of pods is dependent on how aggressively I am increasing the load, so it could be 13, 16 etc.</p>
<p>But I want that the number of pods should always increase in a multiple of 5 and decrease in a multiple of 3. Is this possible?</p>

Gaurav Kumar
<p>Went through documentation and some code, this looks impossible to force horizontal pod autoscaler (HPA) to scale down or up in exact numbers of pods since there's no flags/options for it.</p>
<p><strong>The closest you can get</strong> is to set up <code>scaleDown</code> and <code>scaleUp</code> policies.</p>
<p>Below the example (<strong>note</strong>, this will work with <code>v2beta2</code> api version), this part should be located under <code>spec</code>:</p>
<pre><code>behavior:
  scaleDown:
    stabilizationWindowSeconds: 300
    policies:
    - type: Pods
      value: 3
      periodSeconds: 15
  scaleUp:
    stabilizationWindowSeconds: 0
    policies:
    - type: Pods
      value: 5
      periodSeconds: 15
</code></pre>
<p><strong>What this means:</strong></p>
<ul>
<li><code>scaleDown</code> will be performed at most of 3 pods every 15 seconds.</li>
<li><code>scaleUp</code> will be performed at most of 5 pods every 15 seconds.</li>
<li><code>stabilizationWindowSeconds</code> - The stabilization window is used to restrict the flapping of replicas when the metrics used for scaling keep fluctuating. The stabilization window is used by the autoscaling algorithm to consider the computed desired state from the past to prevent scaling</li>
</ul>
<p>This doesn't guarantee that HPA will scale up or down the exact number of specified pods, it's just a policy. However if workload increase or decrease will happen fast, it should be close to behaviour you'd like to see.</p>
<p><strong>Useful link:</strong></p>
<ul>
<li><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-configurable-scaling-behavior" rel="nofollow noreferrer">Support for configurable scaling behavior</a></li>
</ul>
