Question
Create PersistentVolume called pv-wait that can only be provisioned and mapped when a PersistentVolumeClaim is created which is further consumed by Pod.
Create necessary dependent resources.
Answer
The trick in this question is to create a StorageClass first with volumeBindingMode set to WaitForFirstConsumer.
This binding mode indicates that provisioning and binding occurs once the PersistentVolumeClaim is created. Default binding mode is Immediate.
Create custom StorageClass:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
Next create a PersistentVolume using the custom StorageClass:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-wait
spec:
storageClassName: local-storage
capacity:
storage: 1Gi
accessModes:
- ReadWriteMany
hostPath:
path: "/mnt/data"