utkuozdemir / pv-migrate

CLI tool to easily migrate Kubernetes persistent volumes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement shrinking (reducing) of the Kubernetes PVC size via pv-migrate by replacing the PV

MurzNN opened this issue · comments

Is your feature request related to a problem? Please describe.
Kubernetes doesn't have the functionality to reduce or shrink the PV size.

But we can automate this process and make this feature work via several steps!

We can create a new empty PV with the reduced size, rsync the data to it, and then - replace the old PV to the new one in the PVC.

Describe the solution you'd like
So, here are the steps of how to implement this:

  1. Create a new reduced PVC with a reduced size.
  2. Rsync data to it via the same approach that we already have.
  3. Dump the source PVC configuration.
  4. Store the UUID of the PV in the reduced PVC.
  5. Unbound the PV from the reduced PVC by
kubectl patch pv <your-pv-name> -p '{"spec":{"claimRef": null}}'
  1. Delete the source PVC.
  2. Create a new PVC with the same configuration from the dump but with the reduced size and bounding to it the unbounded PV from step 5.
  3. Profit?

Describe alternatives you've considered
I searched a lot for a ready-to-use tool for this task but found nothing. :(

So, implementing this in the pv-migrate will be a great improvement!

It is a good idea, but I think it's out of scope for this tool. I don't aim to increase the functionality to do more things - rather keep it focused to copying the data.

What you suggest should be doable with a small wrapper, e.g. a bash script, which calls pv-migrate + does what you suggest. Another option would be to create a new cli tool, import this project and use its internals.

Closing as it is out-of-scope for simplicity.