With the storage add-on for MicroK8s, Persistent Volume Claims are by default given storage under /var/snap/microk8s/common/default-storage
on the host system. How
If You want to add your own path to your persistentVolume You can use spec.hostPath.path value
example yamls
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: base
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: Immediate
apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume
labels:
type: local
spec:
storageClassName: base
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
spec:
storageClassName: base
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
kindly reminder
Depending on the installation method, your Kubernetes cluster may be deployed with an existing StorageClass that is marked as default. This default StorageClass is then used to dynamically provision storage for PersistentVolumeClaims that do not require any specific storage class. See PersistentVolumeClaim documentation for details.
You can check your storageclass by using
kubectl get storageclass
If there is no <your-class-name>(default)
that means You need to make your own default storage class.
Mark a StorageClass as default:
kubectl patch storageclass <your-class-name> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
After You make defualt storageClass You can use those yamls to create pv and pvc
apiVersion: v1
kind: PersistentVolume
metadata:
name: task-pv-volume3
labels:
type: local
spec:
storageClassName: ""
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data2"
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim3
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
Based on kubernetes documentation
Once bound, PersistentVolumeClaim binds are exclusive, regardless of how they were bound. A PVC to PV binding is a one-to-one mapping.