Operations 12 min read

Effortlessly Migrate PVCs Across Kubernetes Clusters with pv-migrate

This guide explains how to use the kubectl pv-migrate plugin to move PersistentVolumeClaims between namespaces, clusters, and storage classes, covering offline installation, manifest creation, image preparation, target PVC definition, and a step‑by‑step data migration command.

Linux Ops Smart Journey
Linux Ops Smart Journey
Linux Ops Smart Journey
Effortlessly Migrate PVCs Across Kubernetes Clusters with pv-migrate

In Kubernetes daily operations, stateful applications such as MySQL rely on PersistentVolume (PV) and PersistentVolumeClaim (PVC) for data persistence. When business needs evolve, you may need to migrate a PVC from one cluster/namespace to another and switch to a higher‑performance StorageClass.

The traditional manual process—backup, volume creation, data copy, and application recreation—is time‑consuming and error‑prone. The open‑source kubectl pv-migrate plugin automates cross‑cluster, cross‑namespace, and cross‑StorageClass PVC migration with a single command.

Typical Use Cases

StorageClass migration: move data from a local‑storage class to ceph‑rbd.

Namespace migration: relocate an application and its data to a new namespace during refactoring.

Cluster migration: shift workloads between cloud providers or from a development to a production cluster.

Offline Installation

Prerequisite: krew must be installed. Install the plugin manifest and download the appropriate binary archive.

cat <<'EOF' | tee pv-migrate.yaml > /dev/null
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
  name: pv-migrate
spec:
  version: v2.2.1
  homepage: https://github.com/utkuozdemir/pv-migrate
  platforms:
    - selector:
        matchLabels:
          os: linux
          arch: amd64
      uri: https://github.com/utkuozdemir/pv-migrate/releases/download/v2.2.1/pv-migrate_v2.2.1_linux_x86_64.tar.gz
      sha256: 44b01b1b6c72a2fef6f77f6e61087810cc0cae9e26347afd2baa3fe911374690
      bin: pv-migrate
    # (other platforms omitted for brevity)
  shortDescription: Migrate data across persistent volumes
  description: |
    pv-migrate uses ssh and rsync to copy data across persistent volumes
EOF

Download the binary:

$ wget https://github.com/utkuozdemir/pv-migrate/releases/download/v2.2.1/pv-migrate_v2.2.1_linux_x86_64.tar.gz

Install the plugin via krew:

$ kubectl krew install --manifest ./pv-migrate.yaml --archive ./pv-migrate_v2.2.1_linux_x86_64.tar.gz

Practical pv-migrate Usage

Because the Kubernetes nodes have no external network, pull the required images in advance:

$ docker pull docker.io/utkuozdemir/pv-migrate-rsync:1.0.0
$ docker tag docker.io/utkuozdemir/pv-migrate-rsync:1.0.0 core.jiaxzeng.com/library/pv-migrate-rsync:1.0.0
$ docker push core.jiaxzeng.com/library/pv-migrate-rsync:1.0.0

$ docker pull docker.io/utkuozdemir/pv-migrate-sshd:1.1.0
$ docker tag docker.io/utkuozdemir/pv-migrate-sshd:1.1.0 core.jiaxzeng.com/library/pv-migrate-sshd:1.1.0
$ docker push core.jiaxzeng.com/library/pv-migrate-sshd:1.1.0

Create the destination PVC:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: data-prometheus-monitor-0-copy
  namespace: obs-system
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
  storageClassName: ceph-rbd-storage

Run the migration command:

$ kubectl pv-migrate \
  --source-namespace obs-system --source data-prometheus-monitor-0 \
  --dest-namespace obs-system --dest data-prometheus-monitor-0-copy \
  --helm-set rsync.image.repository=core.jiaxzeng.com/library/pv-migrate-rsync \
  --helm-set sshd.image.repository=core.jiaxzeng.com/library/pv-migrate-sshd \
  --ignore-mounted --log-level DEBUG

The plugin logs the migration progress, copies data (e.g., 54 MB/s), and cleans up temporary resources, finally reporting “Migration succeeded”.

In the cloud‑native era, data is a core asset, and storage migration is essential for business continuity. The lightweight, open‑source kubectl pv-migrate turns a complex, high‑risk operation into a single command, making operations simpler and data safer.

cloud nativeKuberneteskrewstorage classpv-migratePVC migration
Linux Ops Smart Journey
Written by

Linux Ops Smart Journey

The operations journey never stops—pursuing excellence endlessly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.