Cloning a PVC

A new PVC should start as a full copy of an existing one, but the copy is made only if the two claims line up, and otherwise the new one sits Pending. What has to match, and does anything link them afterwards?

Play the animation 5 steps, animated, plays on a computer or a tablet

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, a growth 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. When data-src is deleted, its volume goes too, since its class reclaims with Delete, yet clone-1 keeps its copy untouched. Unlike after a snapshot restore, no VolumeSnapshot stays between them to restore from again.

    Play from step 5

Sources