Volumes

K8s volumes tips and tricks.

Persistent storage

Create StorageClass

Create the yml file:

cat > /tmp/storage-class.yml <<EOF
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

EOF

Deploy it:

kubectl create -f /tmp/storage-class.yml

name: local-storage will be the reference used in the PersistentVolume and PersistentVolumeClaim. You can change the StorageClass name, but remember to update all references below.

Create PersistentVolume

SSH to your Master node and create the folder which will store the volume:

Go back to your kubectl workstation.

Create the yml file:

Deploy it:

Create PersistentVolumeClaim

Create the yml file:

Deploy it:

if by any chance you omitted storageClassName: local-storage then you need to "patch" the StorageClass first:

kubectl patch storageclass local-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

Check if you do not have a default StorageClass patched already, other wise you might see the following error when creating PersistentVolumeClaim:

persistentvolumeclaims "example-local-claim" is forbidden: Internal error occurred: 2 default StorageClasses were found

Deploy a pod using the volume

Create the yml file:

Deploy it:

References

https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/

https://stackoverflow.com/questions/52975887/digitalocean-pod-has-unbound-immediate-persistentvolumeclaims

Persistent storage (AWS)

References

https://portworx.com/basic-guide-kubernetes-storage/

https://itnext.io/efs-persistent-volumes-on-aws-kubernetes-193e0035bbfb

https://kubernetes.io/docs/setup/scratch/#apiserver-pod-template

https://docs.google.com/document/d/17d4qinC_HnIwrK0GHnRlD1FKkTNdN__VO4TH9-EzbIY/edit

Last updated