Persistent_Volumes_and_Claims
Persistent Volumes and Claims
Persistent Volumes
A persistent volume (pv) is a storage abstraction used to retain data longer than the Pod
using it. Pod
s define a volume of type persistentVolumeClaim (pvc)
. The cluster then attaches the persistentVolume
. PVs are not namespaced while PVCs are.
The following are the phases of Persistent Storage:
-
Provision
: Provisioning can be from the PVs created in advance by the cluster administrator or requested from a dynamic provider (Google/AWS, etc). -
Bind
: Binding occurs when a control loop on the master notices the PVC and locates a matching PV. -
Use
: When the bound volume is mounted for thePod
to use and is kept in this phase as long as thePod
requires. -
Release
: Happens when thePod
is done with the volume and an API request to delete the PVC is sent. -
Reclaim
: could be:Retain
: keeps data intact allowing an admin to handle storage and data.Delete
: tells volume plugin to delete the API object as well as storage.Recycle
: runrm -rf /mountpoint
and then makes it available to a new claim.
We can see the PV and PVC:
kubectl get pv
kubectl get pvc
The following specification is a basic declaration of a PV using hostPath
:
apiVersion: v1
kind: PersistentVolume
metadata:
name: 10Gpv01
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/somepath/data01"
Persistent Volume Claim
With a created PV in the cluster, we can write a manifest for a claim and use that claim in the Pod
specification using persistentVolumeClaim
.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 8Gi
In the Pod
:
spec:
containers:
...
volumes:
- name: test-volume
persistentVolumeClaim:
claimName: myclain