Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent PVC from being deleted in K8s

Tags:

kubernetes

I recently encountered an issue where something (which I was not able to identify) deleted a PVC and the corresponding PV in my k8s cluster. The data can be recovered but I have two questions:

  1. Is there some hack to prevent the PVC from being deleted accidentally if someone issues a wrong command which deletes it?
  2. Is it possible to check what command caused the deletion of the PVC via some logs?
like image 480
Axel Chauvin Avatar asked Nov 16 '25 19:11

Axel Chauvin


1 Answers

For question 1, you can set the Reclaim Policy to Retain. This means that the PV and PVC can be deleted but the underlying storage volume will stick around forever (or until you delete it in whatever the underlying system is).

For 2, yes if you have audit logging turned on. https://kubernetes.io/docs/tasks/debug-application-cluster/audit/#audit-backends. Otherwise not really.

like image 167
coderanger Avatar answered Nov 18 '25 19:11

coderanger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!