Auto delete persistant volume claim when a kubernetes job gets completed
Asked Answered
W

1

6

Is there any policy or a way that enable us to auto delete a persistent volume claim when a kubernetes-job (using that claim) gets completed.

FYI: i am creating persistent volume claim using delete policy i.e. on claim deletion the associated persistent volume gets deleted too which is my intended behavior.

only suggest other solutions like (cronjobs for cleaning or kubernetes watch feature) if there is not automated way of doing this, that will be my last option.

Waitabit answered 25/6, 2018 at 12:36 Comment(2)
As I remember, there is no feature like you said. you should implement like cronjob or something. Cheers.Barty
There is no feature which can do this directly but you can try to execute (pre-stop phase) a custom script to achieve the same, as described here. But be careful while doing this as, stopping container is not same as stopping Pod. Test very carefully before you push to prod.Evelunn
F
4

There is no such functionality in Kubernetes to delete a Persistent Volume Claim after a Job has been completed.

One of the ways is to use Cron Job with simple busybox container running bash script, which checks and deletes unused Persistent Volume Claims.

It is not recommended to use custom scripts in "pre-stop phase" in Pod as @techtrainer suggested in comments because if some errors appear before this script, Job will fail and Persistent Volume Claim won’t be deleted.

Frilling answered 25/6, 2018 at 12:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.