Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chris2k20/k8s-pvc-storageclass-migrator
This script automates the process of migrating a Persistent Volume Claim (PVC) to a new storage class in Kubernetes. It creates a temporary PVC, migrates data, replaces the original PVC, and then migrates the data back.
https://github.com/chris2k20/k8s-pvc-storageclass-migrator
k8s pvc storageclass
Last synced: 17 days ago
JSON representation
This script automates the process of migrating a Persistent Volume Claim (PVC) to a new storage class in Kubernetes. It creates a temporary PVC, migrates data, replaces the original PVC, and then migrates the data back.
- Host: GitHub
- URL: https://github.com/chris2k20/k8s-pvc-storageclass-migrator
- Owner: chris2k20
- License: mit
- Created: 2024-07-20T20:44:47.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-18T08:36:16.000Z (about 2 months ago)
- Last Synced: 2024-10-10T16:23:53.933Z (about 1 month ago)
- Topics: k8s, pvc, storageclass
- Language: Shell
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PVC Storage Class Migration Script
This script automates the process of migrating a Persistent Volume Claim (PVC) to a new storage class in Kubernetes. It creates a temporary PVC, migrates data, replaces the original PVC, and then migrates the data back.
## Requirements
### Ubuntu
- kubectl
- yq (version 4.x)
- jq
- [pv-migrate](https://github.com/utkuozdemir/pv-migrate)To install the requirements on Ubuntu:
```bash
# Install kubectl
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl# Install yq
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq# Install jq
sudo apt-get install -y jq# Install pv-migrate
curl -L https://github.com/utkuozdemir/pv-migrate/releases/latest/download/pv-migrate_Linux_x86_64.tar.gz | tar xz
sudo mv pv-migrate /usr/local/bin
```### macOS
- kubectl
- yq (version 4.x)
- jq
- [pv-migrate](https://github.com/utkuozdemir/pv-migrate)To install the requirements on macOS:
```bash
# Install kubectl
brew install kubectl# Install yq
brew install yq# Install jq
brew install jq# Install pv-migrate
brew install utkuozdemir/pv-migrate/pv-migrate
```## Usage
```bash
git clone https://github.com/chris2k20/k8s-pvc-storageclass-migrator
cd k8s-pvc-storageclass-migrator
bash k8s-pvc-storageclass-migrator.sh
```Replace `` with the name of the PVC you want to migrate.
## Demo Output
```
โก56% โ bash k8s-pvc-storageclass-migrator.sh --dest-sc=hcloud-volumes data-wp-www-example-com-mariadb-0
Creating new temporary PVC: data-wp-www-example-com-mariadb-0-tmp
persistentvolumeclaim/data-wp-www-example-com-mariadb-0-tmp created
Migrating data from data-wp-www-example-com-mariadb-0 to data-wp-www-example-com-mariadb-0-tmp...
๐ Starting migration
๐ญ Will attempt 1 strategies: svc
๐ Attempting strategy: svc
๐ Generating SSH key pair
๐ Copying data... 100% |โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| (187 MB/s)
๐ Copying data... 0% | | [0s:0s]
๐งน Cleaning up
๐ Copying data... 100% |โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ|
โจ Cleanup done
โ Migration succeeded
Waiting for the original PVC data-wp-www-example-com-mariadb-0 to be unbound...
PVC data-wp-www-example-com-mariadb-0 is bound to pod pv-migrate-acdeb-sshd-65cb56c6d9-wtcwc.
PVC is still bound. Waiting 10 seconds...
PVC data-wp-www-example-com-mariadb-0 is bound to pod pv-migrate-acdeb-sshd-65cb56c6d9-wtcwc.
PVC is still bound. Waiting 10 seconds...
PVC data-wp-www-example-com-mariadb-0 is bound to pod pv-migrate-acdeb-sshd-65cb56c6d9-wtcwc.
PVC is still bound. Waiting 10 seconds...
Replacing original PVC: data-wp-www-example-com-mariadb-0
persistentvolumeclaim "data-wp-www-example-com-mariadb-0" deleted
persistentvolumeclaim/data-wp-www-example-com-mariadb-0 created
Performing final data migration from data-wp-www-example-com-mariadb-0-tmp to data-wp-www-example-com-mariadb-0...
๐ Starting migration
๐ญ Will attempt 1 strategies: svc
๐ Attempting strategy: svc
๐ Generating SSH key pair
๐ Copying data... 100% |โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ| (106 MB/s)
๐ Copying data... 0% | | [0s:0s]
๐งน Cleaning up
๐ Copying data... 100% |โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ|
โจ Cleanup done
โ Migration succeeded
Cleaning up: Deleting temporary PVC data-wp-www-example-com-mariadb-0-tmp
persistentvolumeclaim "data-wp-www-example-com-mariadb-0-tmp" deleted
PVC migration completed successfully.
```## Notes
- Ensure you have the necessary permissions to manage PVCs in your Kubernetes cluster.
- The script assumes that the `pv-migrate` tool is available in your system PATH.
- Make sure to test the script in a non-production environment before using it on critical data.## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.