<p>I was reading the example at <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/" rel="nofollow noreferrer">kubernetes hpa example</a>. In this example they run with: <code>kubectl run php-apache --image=k8s.gcr.io/hpa-example --requests=cpu=200m --expose --port=80</code>. So the pod will ask for 200m of cpu (0.2 of each core). After that they run hpa with a target cpu of 50%: <code>kubectl autoscale deployment php-apache --cpu-percent=50 --min=1 --max=10</code>. Which mean that the desired milli-core is 200m * 0.5 = 100m. They make a load test and put up a 305% load. Which mean auto scale up to: ceil((3.05 * 200m) / 100m) = 7 pods according to: <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details" rel="nofollow noreferrer">hpa scaling algorith</a>.</p>

<p>This is all good, but we are experimenting with different values and I wonder if it's a good approach.</p>

<p><a href="https://i.stack.imgur.com/VmuJ1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VmuJ1.png" alt="2 options"></a></p>

<p>We opted for a target cpu of 500% (second option). For me, target cpu >= 100% is a wierd concept (maybe I understand wrong also, please correct me as I'm not that familiar with the whole concept), but it slow down scaling compare to the inverted (first option).</p>

<p>The first approach is correct.</p>

<p>The second one is not good for a few reasons:</p>

<ol>
<li><strong>Decision about necessity of scaling up the cluster is taken too late</strong>, when first Pod is already overloaded. If you give only <strong>100 millicores of CPU to one Pod</strong>, but you allow a situation it can use 5 times of what is available, before the decision about scaling up the cluster can be taken. Such system isn't very efficient with load average about 5 per core which means that when 1 process is served in a given time, there are another 4 processes waiting for CPU time. </li>
<li><strong>Same with scaling down the cluster. It isn't very effective either.</strong> Let's say your general CPU usage in your cluster decreased by more than 400 millicores but it is still not enough to remove one replica and scale down the cluster. In first case scenario 4 replicas would be already removed and the cluster scaled down.</li>
</ol>

<p><strong>Another very important thing</strong>. When planning your <strong>Horizontal Pod Autoscaler</strong>, consider total amount of resources available in your cluster so you don't find yourself in a situation when you're run out of resources. </p>

<p><strong>Example:</strong> you have a system with 2-core processors which equals to having 2000 millicores available from perspective of your cluster. Let's say you decided to create following deployment:</p>

<p><code>kubectl run php-apache --image=k8s.gcr.io/hpa-example --requests=cpu=500m --expose --port=80</code></p>

<p>and then <strong>Horizontal Pod Autoscaler</strong>:</p>

<p><code>kubectl autoscale deployment php-apache --cpu-percent=100 --min=1 --max=5</code></p>

<p>This means you allow that more resources can be requested than you're actually have available in your cluster so in such situation 5th replica will never be created.</p>
