Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 296
user11771691 Avatar asked Jul 11 '19 17:07

user11771691


People also ask

What happens when you delete StatefulSet?

Deleting the Pods in a StatefulSet will not delete the associated volumes. This is to ensure that you have the chance to copy data off the volume before deleting it.

Does deleting StatefulSet delete PVC?

The PVC is deleted only when the replica is no longer needed as signified by a scale-down or StatefulSet deletion. This use case is for when data does not need to live beyond the life of its replica.

Does StatefulSet create Replicaset?

StatefulSets serve as controllers, but they don't create ReplicaSets—they create uniquely named pods, according to a specified pattern. The DNS name of a pod includes the ordinal index. Each replica in a StatefulSet has its own state, with a unique persistent volume claim (PVC) created for each pod.


3 Answers

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

like image 77
srinivas kulkarni Avatar answered Sep 27 '22 21:09

srinivas kulkarni


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.

like image 44
Ijaz Ahmad Avatar answered Sep 27 '22 22:09

Ijaz Ahmad


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.

like image 26
iomv Avatar answered Sep 27 '22 21:09

iomv