PVC Migration in Kubernetes: How to Move Persistent Data Across Availability Zones

Learn how to perform PVC migration in Kubernetes across clusters or availability zones without downtime. Step-by-step guide with commands, YAML examples, and best practices for resilient, scalable workloads.

Table of contents
Key Takeaways

1. PVC migration allows moving persistent data between Kubernetes clusters or availability zones without losing information.

2. You can identify, snapshot, and restore PVs using your cloud provider’s storage services.

3. YAML configurations for PV and PVC creation ensure correct storage binding in the target cluster.

4. The migration process involves snapshotting, volume recreation, PV/PVC creation, and pod attachment.

5. This method supports AWS EBS volumes and can be adapted for other cloud providers.

Introduction

In today’s IT world, data is everything, and in the era of DevOps, requirements change frequently. Let’s assume your application is running on one Kubernetes cluster, and for some reason, you need to migrate a PVC (Persistent Volume Claim) from this cluster to another Kubernetes cluster in a different availability zone without losing data.

In this guide, we’ll cover how to migrate PVC across availability zones in Kubernetes, the commands to use, and best practices for cloud providers like AWS.

What are PV, PVC, and Storage Volume?

  • Persistent Volume (PV): A storage resource in Kubernetes that exists independently of the pod lifecycle. Even if the pod is deleted, the data remains in the PV.
  • Persistent Volume Claim (PVC): A request for storage by a user, specifying size, access mode, and other configurations.
  • Storage Volume: A virtual disk (block storage) provided by your cloud provider for persistent data storage.

Steps to Migrate PVC Across Availability Zones

1. Identify the PVC Attached to Your Pod

kubectl get po <pod-name> -o yaml

2. Find the PV Bound to the PVC

kubectl get pvc <pvc-name>

3. Get the Volume ID and Zone Info

kubectl describe pv <pv-name>

Check the annotations for the volume ID and the availability zone.

4. Snapshot and Create a New Volume

  • Create a snapshot of the existing volume in your cloud provider console (e.g., AWS EBS Snapshot).
  • Create a new volume from that snapshot in the desired availability zone.
  • Add the label:
KubernetesCluster: <clustername>

Note the new volume ID.

5. Create a PV from the New Volume

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
  labels:
    type: persistent-volume
spec:
  capacity:
    storage: 3Gi
  accessModes:
    - ReadWriteOnce
  awsElasticBlockStore:
    volumeID: <YOUR STORAGE VOLUME ID>
    fsType: ext4

6. Create a PVC Bound to the New PV

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
  labels:
    type: persistent-volume-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
  selector:
    matchLabels:
      type: persistent-volume

7. Attach PVC to a Pod

apiVersion: v1
kind: Pod
metadata:
  name: pv-pod
spec:
  volumes:
    - name: my-pv
      persistentVolumeClaim:
        claimName: my-pvc
  containers:
    - name: task-pv-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: my-pv

Congratulations! 🎉 You have successfully migrated a PVC from one Kubernetes cluster to another across different availability zones.

Best Practices for PVC Migration

  • Always take backups before initiating migration.
  • Use ReadWriteOnce volumes for single-node attachment; adjust for ReadWriteMany if needed.
  • Check volume type compatibility in the target availability zone.
  • For faster automation, consider Kubernetes VolumeSnapshot APIs if your cloud provider supports them.

Conclusion

PVC migration in Kubernetes is a crucial skill for moving persistent data across clusters or availability zones without downtime or data loss. By carefully identifying PVC/PV details, creating snapshots, and provisioning new volumes, you can ensure a smooth migration process. This approach not only supports disaster recovery but also enables scaling, multi-region deployments, and infrastructure upgrades while keeping workloads resilient and highly available.

💡
Coming SoonDevtron’s Agentic AI feature will help automate tasks like PVC migration, resource provisioning, and YAML generation intelligently, saving you hours of manual work.

FAQ

How do you migrate a Persistent Volume Claim (PVC) across availability zones in Kubernetes?

You can migrate a PVC by identifying the existing volume, creating a snapshot, restoring it in the target zone, creating a new PV using that volume, and then binding it to a new PVC for use in another pod.

What is the role of PV and PVC during Kubernetes storage migration?

A PV represents the actual cloud-based storage, while the PVC is a request for that storage by the pod. During migration, the PVC is recreated and linked to a newly provisioned PV based on the volume snapshot.

Can AWS snapshots be used to transfer PVC data across regions or zones?

Yes, AWS EBS snapshots allow you to replicate PVC data across zones. You can create a snapshot of the existing volume, restore it in a different zone, and then use it to create a new PV in the target Kubernetes cluster.

How do you attach a migrated PVC to a Kubernetes pod?

You can attach the PVC by referencing it in the pod's volume section and mounting it inside the container. This enables the pod to access the restored data using the same mount path without any data loss.

visibility-guide

Related articles

Related articles