apiVersion: v1 kind: PersistentVolume metadata: name: local-storage spec: capacity: storage: 10Gi # volumeMode field requires BlockVolume Alpha feature gate to be enabled. volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Persist storageClassName: local-storage local: path: /var/k8s/LOCAL_STORAGE nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - k8sworker1 - k8sworker2 - k8sworker3 - docker-for-desktop --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: local-storage-claim spec: storageClassName: local-storage accessModes: - ReadWriteOnce resources: requests: storage: 3Gi |
Make our local-storage class the default
kubectl patch storageclass local-storage -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
Make a claim using the default
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: local-storage-claim spec: storageClassName: "" accessModes: - ReadWriteOnce resources: requests: storage: 3Gi |
Make a claim by specifying the storage class
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: local-storage-claim spec: storageClassName: local-storage accessModes: - ReadWriteOnce resources: requests: storage: 3Gi |
ssh k8sworker1
sudo mkdir -p /var/k8s/LOCAL_STORAGE
Repeat for all nodes requiring local storage.
From master node
kubectl apply -f localstorage.yml
Reference | URL |
---|---|
Volumes - Kubernetes | https://kubernetes.io/docs/concepts/storage/volumes/ |
Local Persistent Volumes for Kubernetes Goes Beta | https://kubernetes.io/blog/2018/04/13/local-persistent-volumes-beta/ |
Change Default Storage Class | https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class/ |