1

I have a Kubernetes deployment which can have multiple replica pods. I wish to horizontally increase and decrease the pods based on some logic in my python application (not custom metrics in hpa).

I have two ways to this:

  1. Using Horizontal Pod Autoscalar and changing minReplicas, maxReplicas though my application by using kubernetes APIs
  2. Directly updating the "/spec/replicas" field in my deployment using the APIs

Both the above things are working for upscale and downscale.

But, when I scale down, I want to remove a particular Pod, and not any other pod.

If I update the minReplicas maxReplicas in HPA, then it randomly deletes a pod. Same when I update the /spec/replicas field in the deployment.

How can I delete a particular pod while scaling down?

user5155835
  • 4,392
  • 4
  • 53
  • 97
  • 3
    I don't know an answer for this, but I think this is anti-pattern. It shouldn't make a difference what pod gets removed. – Akalanka Weerasooriya Jul 04 '20 at 15:18
  • Is there a specialreason for removin one specific pod? The pod it is located in a certain host or vm? – Armando Cuevas Jul 04 '20 at 16:39
  • @ArmandoCuevas I have certain data/requests tied to a certain replica pod, so I want to remove only a particular pod – user5155835 Jul 05 '20 at 07:48
  • @AkalankaWeerasooriya I have certain data/requests tied to a certain replica pod, so I want to remove only a particular pod – user5155835 Jul 05 '20 at 07:48
  • You could allocate the pods in a specific node using [podAffinity](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/) an then remove the pods from this node. This solution works for you? – Mr.KoopaKiller Jul 06 '20 at 09:59

1 Answers1

0

I am not aware of any way to ensure that a particular pod in a ReplicaSet will be deleted during a scale down. You could achieve this behavior with a StatefulSet which will always delete the last pod on scale down.

For example, if we had a StatefulSet foo that was scaled to 3 we would have pods:

  • foo-0
  • foo-1
  • foo-2

And if we scaled the StatefulSet to 2, the controller would delete foo-2. But note that there are other limitations to be aware of with StatefulSet.

Jason Kincl
  • 968
  • 6
  • 11