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
