Search code examples
kuberneteskubernetes-podkubernetes-statefulset

Kubernetes : How to delete a specific pod managed by StatefulSet without it being recreated?


I have a StatefulSet with 2 pods. It has a headless service and each pod has a LoadBalancer service that makes it available to the world.

Let's say pod names are pod-0 and pod-1.

If I want to delete pod-0 but keep pod-1 active, I am not able to do that.

I tried

kubectl delete pod pod-0

This deletes it but then restarts it because StatefulSet replica is set to 2.

So I tried

kubectl delete pod pod-0
kubectl scale statefulset some-name --replicas=1

This deletes pod-0, deletes pod-1 and then restarts pod-0. I guess because when replica is set to 1, StatefulSet wants to keep pod-0 active but not pod-1.

But how do I keep pod-1 active and delete pod-0?


Solution

  • This is not supported by the StatefulSet controller. Probably the best you could do is try to create that pod yourself with a sleep shim and maybe you could be faster. But then the sts controller will just be unhappy forever.