2

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.

2 Answers2

2

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
0

It is a bit tricky, but I would try to create the volumes manually with the proper size, fill them with the data from the bigger volumes and then redeploy having the application attach to the new volumes.

I know that the answer is pretty generic but how to do it will depend on what capabilities and access to the underlying infrastructure you have.

I'm not familiar with Ceph backed volumes but if you are able to create the new ones in Ceph, copy from the bigger volumes to the new ones directly within Ceph and then create the PV manually but configured to use the smaller volumes (so it does not provision the Ceph storage when creating the PV) that would probably be the easiest option.

Gerard Garcia
  • 1,554
  • 4
  • 7
  • I don't direct have access to the Ceph backend. But in general you're aproach seems reasonable to me. But I have a further question: Without that option I would guess that I need to use `kubctl cp` for such a task. Or is there another option how to get and copy the data to the new volume? – Philipp Hölscher May 20 '22 at 12:38