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

1/22/2020

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?

-- crossvalidator
kubernetes
kubernetes-pod
kubernetes-statefulset

2 Answers

1/23/2020
  • Statefulset always creates the pods with indices 0..(replica-1).
  • If you really want to have a finer control over individual pods, i guess you would need to create separate STS objects (with replica = 1)
-- pr-pal
Source: StackOverflow

1/23/2020

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.

-- coderanger
Source: StackOverflow