Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shrink Kubernetes persistent volumes

I do have multiple persistent volumes which need to be shrinked to reduce the hosting costs. I already figured out that Kubernetes does not provide such an option. I also tried to clone or the restore the volumes from an snapshot to a new smaller volume - with the same result (requested volume size XXX is less than the size XXX for the source snapshot).

Nevertheless I need a solution or workaround to get this done.

The cluster is deployed with Rancher and the volumes are mounted to a Ceph Cluster. Everything is provided by an external hoster.

like image 764
Philipp Hölscher Avatar asked Nov 05 '25 10:11

Philipp Hölscher


1 Answers

Finally I achieved what needed with the following steps (still tricky and manual work):

  • Stop running pod (otherwhise you could not use the volume in the next steps)
  • Create the a new PVC with the desired capacity (ensure that the spec and label matches the exisitng PVC)
  • Run this Job https://github.com/edseymour/pvc-transfer
    • In the spec of the job-template.yaml set the source and destination volume
  • Set the ReclaimPolicy on the new created pv to Retain. This will ensure that the pv won't be deleted after we delete the temp pvc in the next step
  • Delete the source and destination pvc
  • Create a new pvc with the old name and the new storage capacity
  • On the new pv point the claimRef to the new pvc
like image 68
Philipp Hölscher Avatar answered Nov 07 '25 16:11

Philipp Hölscher



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!