Kubernetes Persistent Volumes

October 20, 2019

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 or in other words 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: sample-pvc
spec:
  storageClassName: $nameOfCreatedStorageClass
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 200Gi