<p>I have a minimum number of replicas set to 3, maximum 10 and the number of requested replicas as 6. When I deploy, the replicaSet looks good, and I have 6 pods running as expected.</p>
<p>However, after a few minutes I get this message- &quot;Scaled down replica set my-first-app to 3&quot;. It then terminates my pods so I am only left with 3. How do I stop it doing this? I want to have 6 replicas.</p>

Caitlin Hamilton
<p>The <code>HorizontalPodAutoscaler</code> (which I assume you are talking about, as the <code>ReplicaSet</code> resource would not actually be able to scale your Pods horizontally) automatically scales down resources based on the configured metrics (e.g. CPU usage, Memory usage).</p>
<p>High level it uses the following algorithm to determine the number of replicas:</p>
<pre><code>desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]
</code></pre>
<p>It then checks whether the <code>desiredReplicas</code> is larger than the minimum number of replicas required.</p>
<p>See the <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">docs on the Horizontal Pod Autoscaler</a> for more details.</p>
<p>To answer your question: If you always want 6 Pods at the very minimum, just make sure the minReplicas are set to 6, e.g.:</p>
<pre><code>apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: hpa-example
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: deployment-example
  minReplicas: 6
  maxReplicas: 10
  targetCPUUtilizationPercentage: 70
</code></pre>
