Volumes
Configured at the container level. Each container spec must configure its own volume.
Trouble for multi container pods!
A volume gets destroyed with the pod. <-- Is this true?
todo! Test!
A Volume enables safe container restart and allows sharing of data across containers, whereas a PV enables safe Pod termination or restart.
Persistent Volumes
PVs are a large pool of storage that pods can request pieces of
A persistent volume is a large cluster-wide volume , wher ea slice of it is requested by a pod using a Persistent Volume Claim
Modes:
- ReadOnlyMany
- ReadWriteOnce
- ReadWriteMany
Specify the total storage / capacity
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-vol1
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
awsElasticBlackStore:
volumeId: {volId}
fsType: ext4
Persistent Volume Claims
Admins create PVs, Users create PVCs
K8s will bind a PVC to a PV based on reuqests set on the volume. Every claim is bound to a volume. During the bdining process, k8s tries to find a volume that has sufficient space during the claim. as well as other requirements like Access Mode, Volume Mode, Storage, Class, and labels & selectors.
There is a 1:1 relationship between claims & volumes.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
kubectl get pvc
kubectl delete pvc
Reclaim policy
persistentVolumeReclaimPolicy: Retain
Not available for use by any other claims
persistentVolumeReclaimPolicy: Delete
Goodbye volume
persistentVolumeReclaimPolicy: Recycle
Re-use the existing storage / scrub it, and use it again
Static vs Dynamic Volume Provisioning
Static:
aws ebs create volume
Then create a PV with the ID from the create command
This is where storage classes come in.
Dynamic Provisioning
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: google-storage
provisioner: kubernetes.io/gce-pd # Or other
parameters:
... specific to the storageclass
With this, we don't need a PV definition. The storage class will do it when it is created.
In the PVC Definition, simply add
storageClassName: google-storage
Storage classes create the PV for you!