<p>Having a HPA configuration of <code>50%</code> average <code>CPU</code></p>
<pre><code>kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10
</code></pre>
<p>I found the problem that I have only <code>one</code> pod receiving traffic so the <code>CPU</code> is higher than <code>50%</code> of request cpu.</p>
<p>Then start auto scaling up new pods, but those sometimes are not receiving yet any traffic, so the cpu consumption is very low.</p>
<p>My expectations was to see those pods that dont use any cpu to be scale down at some point(how much it should take?), but it's not happening, and I believe the reason is, that first condition of one pod cpu use, higher than 50% is forcing to keep those pods up.</p>
<p>What I need is to scale up/down those pods, until they can start receiving traffic, which it depends on in which node they are deployed.</p>
<p>Any suggestion of how to accomplish this issue?</p>

paul
<p><strong>HPA CPU Utilization:</strong></p>
<p>The targetCPUUtilizationPercentage of 50 means that if average CPU utilization across all Pods goes up above 50% then HPA would scale up the deployment and if the average CPU utilization across all Pods goes below 50% then HPA would scale down the deployment if the number of replicas are more than 1. This is how it works,</p>
<p>I just checked the code and found that targetUtilization percentage calculation uses resource request. You can refer to below code:</p>
<pre><code>currentUtilization = int32((metricsTotal * 100) / requestsTotal)
</code></pre>
<p>Here is the link <a href="https://github.com/kubernetes/kubernetes/blob/v1.9.0/pkg/controller/podautoscaler/metrics/utilization.go#L49" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/blob/v1.9.0/pkg/controller/podautoscaler/metrics/utilization.go#L49</a></p>
<p>There is an official walkthrough focusing on HPA and it's scaling:</p>
<p><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">Kubernetes.io: Docs: Tasks: Run application: Horizontal pod autoscale: Walkthrough</a></p>
<blockquote>
<p><strong>Support for configurable scaling behavior</strong></p>
<p>Kubernetes v1.23 [stable] (the autoscaling/v2beta2 API version
previously provided this ability as a beta feature) If you use the v2
HorizontalPodAutoscaler API, you can use the behavior field (see the
API reference) to configure separate scale-up and scale-down
behaviors. You specify these behaviours by setting scaleUp and / or
scaleDown under the behavior field. You can specify a stabilization
window that prevents flapping the replica count for a scaling target.
Scaling policies also let you controls the rate of change of replicas
while scaling.</p>
<p><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#configurable-scaling-behavior" rel="nofollow noreferrer">Kubernetes.io: Docs: Tasks: Run application: Horizontal pod autoscale:
Support for configurable scaling behavior</a></p>
</blockquote>
<p>You could use newly introduced fields like <code>behavior</code> and <code>stabilizationWindowSeconds</code> to your workload to your specific needs.</p>
