utkuozdemir / pv-migrate

CLI tool to easily migrate Kubernetes persistent volumes
Apache License 2.0
1.62k stars 82 forks source link

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

Closed MurzNN closed 5 months ago

MurzNN commented 9 months ago

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}}'
  6. Delete the source PVC.
  7. 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.
  8. 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!

utkuozdemir commented 9 months ago

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.

utkuozdemir commented 5 months ago

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