Using Persistent Disks with Multiple Readers

This page explains how to add a persistent disk to your cluster using the ReadOnlyMany access mode so that multiple Pods on different nodes can mount the disk for reading.

For more information, refer to the documentation on persistent volume access modes.

Creating PersistentVolume

In order to use your disk as ReadOnlyMany, you must create a new Persistent Volume and PersistentVolumeClaim for the disk with the accessModes fields set to ReadOnlyMany:

readonly-pv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-readonly-pv
spec:
  storageClassName: ""
  capacity:
    storage: 10G
  accessModes:
    - ReadOnlyMany
  gcePersistentDisk:
    pdName: my-test-disk
    fsType: ext4
    

readonly-pvclaim.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-readonly-pvc
spec:
  accessModes:
    - ReadOnlyMany
  resources:
    requests:
      storage: 30Gi
    

Then, when using this PVC in your workloads, you need to specify readOnly: true on the Pod specification:

volumes:
- name: my-volume
  persistentVolumeClaim:
    claimName: my-readonly-pvc
    readOnly: true

Now, you can have multiple Pods on different nodes that can all mount this PVC in read-only mode. Note that you can't attach Persistent Disks in write mode on multiple nodes at the same time. See Deployments Vs. StatefulSets.

Was this page helpful? Let us know how we did:

Send feedback about...

Kubernetes Engine