How do I stop replicaSet terminating requested number of pods

241 views Asked by At

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.

However, after a few minutes I get this message- "Scaled down replica set my-first-app to 3". 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.

1

There are 1 answers

0
Blokje5 On BEST ANSWER

The HorizontalPodAutoscaler (which I assume you are talking about, as the ReplicaSet 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).

High level it uses the following algorithm to determine the number of replicas:

desiredReplicas = ceil[currentReplicas * ( currentMetricValue / desiredMetricValue )]

It then checks whether the desiredReplicas is larger than the minimum number of replicas required.

See the docs on the Horizontal Pod Autoscaler for more details.

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.:

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