Dynamic Provisioning is when you can ask Kubernetes to create a volume of a specific storage class, and kubernetes can create the required storage on the backend dynamically, based on the PV definition.
This is done by creating a storage class.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: google-storage
provisioner: kubernetes.io/gce-pd
volumeBindingMode: WaitForFirstConsumer
paremeters:
type: pd-standard [pd-standard | pd-ssd]
replication-type: none [none|regional-pd]
This will use the stroage class defined above. In practice, we don't need the PV, since the provisioning will be done via the Storage Class we created above.
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-vol1
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 500Mi
gcePersistentDisk:
pdName: pd-disk
fsType: ext4
apiVersion: vi
kind: PersistentVolumeClaim
metadata:
name: myclaim
spec:
accessModes:
- ReadWriteOnce
storageClassName: google-storage #by using the storageClassName, we don't have to use a PV, as the StorageClass definition will take care of creating the PV and underlying storage on the backend.
resources:
requests:
storage: 500Mi
apiVersion: vi
kind: Pod
metadata:
name: random-number-generator
spec:
containers:
- name: alpine
image: alpine
command: ["/bin/sh", "-c"]
args: ["shuf -i 0-100 -n 1 >> /opt/log"]
volumeMounts:
- name: data-volume
mountPath: /opt
volumes:
- name: data-volume
persistentVolumeClaim:
claimName: myclaim
The above pod will use the persistentVolumeClaim my claim, which has been created using a storage class definition. The Storage Class Definition is identified within the PVC by using the storageClassName: google-storage
line in the yaml.
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: delayed-volume-sc
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer