liveBook · Manning

Volume cloning

As explained in Kubernetes in Action, Second Edition

Volume cloning is the creation of a new PersistentVolume initialized from an existing PersistentVolume or its PersistentVolumeClaim.

Volume cloning creates a new PersistentVolume initialized from an existing PersistentVolumeClaim and its associated PersistentVolume. It is useful when dynamic provisioning would otherwise create an empty volume, such as a ReadOnlyMany claim that needs prepopulated data. section 10.2.4

The cloning workflow is straightforward:

  • Define a PersistentVolumeClaim with dataSourceRef pointing to the source claim using kind PersistentVolumeClaim and its name. section 10.2.4
  • Request the desired access mode and storage size; provisioning initializes the new volume from the data source before mounting it into pods. section 10.2.4
  • Mount the new claim read-only when sharing the cloned data through ReadOnlyMany. section 10.2.4

Clone a claim for read-only access

A new claim can request 1Gi with ReadOnlyMany and use demo-read-write-once as its source. A pod then mounts demo-read-only-many with readOnly: true and can see files created on the source volume. section 10.2.4

Listing 10.5 Initializing a PersistentVolumeClaim with another PersistentVolumeClaim
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demo-read-only-many
  labels:
    app: demo-read-only-many
spec:
  resources:
    requests:
      storage: 1Gi
  accessModes:             #1
  - ReadOnlyMany           #1
  dataSourceRef:                     #2
    kind: PersistentVolumeClaim      #2
    name: demo-read-write-once       #2

Inspect the complete PersistentVolumeClaim manifest that initializes a claim from another PersistentVolumeClaim. section 10.2.4

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains the dataSourceRef configuration and provisioning sequence, but does not detail storage-provider implementation.
Examples
Uses demo-read-write-once as the source and demonstrates a demo-read-only-many claim with a read-only pod.
What it assumes
Assumes familiarity with PersistentVolumeClaims and dynamic provisioning while teaching the dataSourceRef pattern directly.
What you can do after
Configure a cloned PersistentVolumeClaim with dataSourceRef and mount the resulting volume in a pod.
How it connects
Connects volume cloning with PersistentVolumeClaim, PersistentVolume, dynamic provisioning, data sources, and access modes.

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.