Have you faced a situation where you need to move data across two persistent volumes, and you weren't so sure how to achieve this? Recently, a German Cloud engineer Utku Özdemir decided to help the community with a CLI Tool/kubectl plugin, pv-migrate, to resolve the problem of migrating persistent volumes.
Table of Contents
- Installing PV-Migrate
- Methods of Migrating Persistent Volumes on Kubernetes
- How to Migrate Persistent Volumes on Kubernetes with pv-migrate
- Conclusion
Installing PV-Migrate
At the time of writing,pv-migrate v1.0.1 is the latest version and we are running the binary for Linux.
Alternatively, you might be running it on MacOS/Windows or even just need a Docker image with this pv-migrate’s binary pre-installed. If that's the case here’re the installation instructions.
Methods of Migrating Persistent Volumes on Kubernetes
pv-migrate uses different methods to migrate persistent volumes on Kubernetes:
- lbsvc: Load Balancer Service, this will run rsync+ssh over a Kubernetes Service type LoadBalancer. This is the method you want to use if you're migrating PVC from different Kubernetes clusters.
- mnt2: Mounts both PVCs in a single pod and runs a regular rsync. This is only usable if source and destination PVCs are in the same namespace.
- svc: Service, Runs rsync+ssh in a Kubernetes Service (ClusteRIP). Only applicable when the source and destination PVCs are in the same Kubernetes cluster.
Note that when you run the command explained below, you don't need to specify the method as it will try all of them and figure out on its own which one to use.
How to Migrate Persistent Volumes on Kubernetes with pv-migrate
For this guide, we had two PVCs similar to the diagram below that shows the migration operation we were trying to accomplish:
Once you have downloaded and installed the CLI, you may now run the following code snippet (don't hesitate to run pv-migrate migrate --help if you're looking at more parameters):
My two PVCs shown by k9s:
For a brief moment, you can see the pod created
Conclusion
For DevOps Engineers, Kubernetes is not an unknown territory. Some of you might have to deal with expanding a PVC where the StorageClass or provisioner doesn't support volume expansion Moving to another cloud provider, or even simply moving data across two PVCs in the same cluster like the example we've presented above.
We hope that pv-migrate will be useful to you as we’ve found it really resourceful for our projects.
You may also be interested in:
Docker Compose vs Kubernetes: The Top 4 Main Differences
Best CI/CD Tools for DevOps: A Review of the Top 10
Single-Cloud vs Multi-Cloud: 7 Key Differences
Why You Need a DevOps Consultant
How to Run a Docker Container on the Cloud: Top 5 CaaS Solutions
Container Security: Top 5 Best Practices for DevOps Engineers
More cost-effective than hiring in-house, with Nearshore Boost, our nearshore software development service, you can ensure your business stays competitive with an expanded team and a bigger global presence, you can be flexible as you respond to your customers’ needs.
Learn more about our services by booking a free consultation with us today!