Storage

Volumes

Allows for persistent data.

Use spec.containers[*].volumeMounts and spec.volumes:

Volumes

With basic hostPath, data is stored directly on EACH node, not shared.

Various volume types exist we can use.

PersistentVolumes

Lets us store data centrally in a pool.

We then claim the data with a persistent volume claim (PVC)

kind: PersistentVolume
apiVersion: v1
metadata:
  name: pv-vol1
spec:
  accessModes: [ "ReadWriteOnce" ]
  capacity:
   storage: 1Gi
  hostPath:
   path: /tmp/data

Persistent Volumes

Persistent Volume Claims

Looks for matching claims.

We can select one ourselves with labels and selectors.

PV and PVC are one to one

If one cannot be matched with the required resources the PVC will stay in pending state

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  accessModes: [ "ReadWriteOnce" ]
  resources:
   requests:
     storage: 1Gi

Once PVC deleted we can choose to automatically delete the underlying PV, retain it, or recycle it.

Persistent Volumes

Storage Classes

Provisioner dynamically provisions when we need storage.

sc-definition.yaml

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
   name: google-storage
provisioner: kubernetes.io/gce-pd

Creates a pv for us automatically when we create a claim if we associate it:

pvc-definition.yaml

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: myclaim
spec:
  accessModes: [ "ReadWriteOnce" ]
  storageClassName: google-storage
  resources:
   requests:
     storage: 500Mi

Last updated