this has been revisted

In short, a Persistent Volume or pv (Kubernetes shorthand), is a storage resource for Kubernetes. Once a pv is set up it can be bound/reserved by a Persistent Volume Claim or pvc.

Normally you would have to provision a pv before you set up your pvc, but if you set up a StorageClass resource in your cluster, when you make a pvc that uses the storageClassName, Kubernetes will dynamically create that pv for you and bind your pvc to it.

pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sample-pvc
spec:
  storageClassName: $nameOfCreatedStorageClass
  resources:
    requests:
      storage: 200Gi
  accessModes:
    - ReadWriteOnce

Take a close look at where we have for accessModes. There are other options you can use which allow the following:

  • ReadWriteOnce: the volume can be mounted as read-write by a single node. ReadWriteOnce access mode still can allow multiple pods to access the volume when the pods are running on the same node.
  • ReadOnlyMany: the volume can be mounted as read-only by many nodes.
  • ReadWriteMany: the volume can be mounted as read-write by many nodes.
  • ReadWriteOncePod: the volume can be mounted as read-write by a single Pod. Use ReadWriteOncePod access mode if you want to ensure that only one pod across whole cluster can read that PVC or write to it. This is only supported for CSI volumes and Kubernetes version 1.22+.