Cloning a PVC

What has to match before Kubernetes will clone a volume? A clone is an ordinary PVC whose dataSource names an existing claim, made only when the two fit: the same namespace and volumeMode, a size at least the source, and a source that is Bound and not being deleted, while the class may differ if its driver is the same. The storage system duplicates the volume server-side with no VolumeSnapshot in between, and afterwards nothing links the clone to its source.

Play the animation 5 steps, animated, best on a wide screen

Cloning a PVC, Kubernetes diagram

Cloning a PVC, step by step

  1. You create clone-1, an ordinary claim with one extra field: its dataSource names the existing claim data-src, of kind PersistentVolumeClaim. The external-provisioner for the driver picks it up as a clone request, which it serves only if the driver reports CLONE_VOLUME.

    Play from step 1
  2. The new claim must fit its source: the same namespace, as dataSource carries none and a cross-namespace dataSourceRef is alpha, a source Bound and not being deleted, the same volumeMode, at least the source size, and any class of the same driver. Any misfit leaves clone-1 Pending.

    Play from step 2
  3. Every row passes, so the provisioner calls CreateVolume on the driver with the source volume as content. The backend makes an exact duplicate server-side, grown to 20Gi, which CSI lets a driver refuse. No VolumeSnapshot object is created, and on Ceph RBD no data passes through a Node.

    Play from step 3
  4. A PV is created for the new volume and clone-1 binds to it, in its own StorageClass rbd-retain. Now that it is Bound, the cloning-protection finalizer on data-src stops holding its deletion, and clone-1 can be used, snapshotted, cloned again or deleted without touching data-src.

    Play from step 4
  5. Nothing links the two afterwards: dataSource only seeded the volume. Delete data-src, and since its class reclaims with Delete its volume goes too, yet clone-1 keeps its copy untouched. That is the line against a snapshot restore: no VolumeSnapshot stays between them to restore from again.

    Play from step 5

Sources