What happens to persistent volume if the StatefulSet got deleted and re-created?

7/11/2019

I made a Kafka and zookeeper as a statefulset and exposed Kafka to the outside of the cluster. However, whenever I try to delete the Kafka statefulset and re-create one, the data seemed to be gone? (when I tried to consume all the message using kafkacat, the old messages seemed to be gone) even if it is using the same PVC and PV. I am currently using EBS as my persistent volume.

Can someone explain to me what is happening to PV when I delete the statefulset? Please help me.

-- user11771691
apache-kafka
kubernetes

3 Answers

11/26/2019

I assume your scenario is that you have a statefulset which has got a persistentvolumeclaim definition in it - or it is just referencing an existing volume - and you try to delete it.

In this case the persistent volume will stay there. Also the pvc won't disappear;

This is so that you can, if you wanted to, remount the same volume to a different statefulset pod - or an update of the previous one thereof.

If you want to delete the persistent volume you should delete the pvc and the buond PVs will disappear.

-- iomv
Source: StackOverflow

7/11/2019

I would probably look at how the persistent volume is created. If you run the command kubectl get pv you can see the Reclaim policy, if it is set to retain, then your volume will survive even when stateful set is deleted

-- srinivas kulkarni
Source: StackOverflow

7/11/2019

This is the expected behaviour , because the new statefulSet will create a new set of PVs and start over. ( if there is no other choice it can randomly land on old PVs as well , for example local volumes )

StatefulSet doesn't mean that kubernetes will remember what you were doing in some other old statefulset that u have deleted.

Statefulset means that if the pod is restarted or re-created for some reason, the same volume will be assigned to it. This doesn't mean that the volume will be assigned across the StatefulSets.

-- Ijaz Ahmad Khan
Source: StackOverflow