How can I change a Kubernetes StorageClass reclaimPolicy from Delete to Retain without losing data?
Asked by
CuriousCoder123
Hey everyone! I currently have a StorageClass set to reclaimPolicy: Delete in my Kubernetes cluster. I'm looking to change it to Retain so that I don't lose any persistent volume data when I delete PVCs. I'm a bit worried about the data in the PVCs that are already using this StorageClass. How can I safely make this change?
Answers
You can't change the `reclaimPolicy` directly on the StorageClass since itโs immutable. But you can edit the Persistent Volume (PV) that it creates to change the `reclaimPolicy` to Retain, and youโll be fine! Just make sure to set up a new StorageClass with `reclaimPolicy: Retain` for the future.
If youโre worried about existing data, you might consider migrating it safely. One way could be to mount both the old and new PVs in a pod and use an initContainer to transfer the data between them. Thatโs just one approach, but itโs worth considering!
Reply to this answer
Add your answer
Answers are reviewed before publication.
TechGuru99: Actually, itโs simpler than that! Just edit the PV directly and change the `reclaimPolicy` to Retain. This way, you wonโt lose any data and you donโt need to manually synchronize anything!