liveBook · Manning

Data source

As explained in Kubernetes in Action, Second Edition

A data source is an origin object from which a newly provisioned PersistentVolume is initialized with data.

A data source is an origin object used to initialize a newly provisioned PersistentVolume. Dynamic provisioning otherwise creates an empty volume, so a data source makes prepopulated read-only storage possible. section 10.2.4

A PersistentVolumeClaim can use another PersistentVolumeClaim as its data source. Set dataSourceRef with kind PersistentVolumeClaim and the source claim’s name; the associated PersistentVolume supplies the initial data. section 10.2.4

Clone a claim for read-only readers

A claim requesting ReadOnlyMany can reference demo-read-write-once through dataSourceRef. Mount the resulting claim with readOnly: true so reader pods see the files copied from 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

Example PersistentVolumeClaim manifest using another PersistentVolumeClaim as its data source. section 10.2.4

Listing 10.6 A pod using a shared PersistentVolume in read-only mode
apiVersion: v1
kind: Pod
metadata:
  generateName: demo-read-only-many-
  labels:
    app: demo-read-only-many
spec:
  volumes:
  - name: volume
    persistentVolumeClaim:              #1
      claimName: demo-read-only-many    #1
      readOnly: true                    #1
  containers:
  - name: main
    image: busybox
    command:
    - sh
    - -c
    - |
      echo "I can read from the volume; these are its files:" ;      #2
      ls /mnt/volume ;       #2                                       
      sleep infinity         #2                                      
    volumeMounts:
      - name: volume
        mountPath: /mnt/volume    ...

Example pod manifest mounting the initialized claim in read-only mode. section 10.2.4

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines dataSourceRef and demonstrates claim cloning, while focusing on PersistentVolumeClaim sources rather than other source types.
Examples
Uses demo-read-write-once to initialize demo-read-only-many and populate reader pods with existing files.
What it assumes
Assumes PersistentVolumeClaim and dynamic provisioning concepts, while explaining why newly provisioned volumes need prepopulation for read-only use.
What you can do after
Apply it via Kubernetes manifests to clone a claim and mount the initialized result read-only.
How it connects
Connects PersistentVolumeClaims with PersistentVolumes, dynamic provisioning, cloning, and access modes.

Also explained in

Compare how 13 books explain data source →

Related concepts

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.