I have a stateful set with persistent volume.
If I do kubectl rollout restart statefulset
pods are recreated and persistent volumes are reclaimed, as expected.
Hovewer, I need to create a cron job that once every now and then will do a rolling restart of pods and also will clean persistent volumes(or recreate them). So what I want to achieve is job stopping one pod at a time, cleaning/deleting its persistent volume and then creating a new pod(or reusing the same one) with empty pvc and only after that pod is up it will proceed to a next one.
Deleting stateful set and creating it again is not an option cause I need to have 0 downtime (assuming there is more then 1 pod in replica set).
One of the options I considered was to configure cron hob to first patch existing configuration so that it removes persistent volume during rollout restart, does an actual rollout restart and then patches it again with a revert change. However not sure which property should I change for that and also wanted to make sure there isn’t an easier way to achieve a similar behavior.