For this example, we will use Docker Desktop Kubernetes cluster, and we will create a hostPath Persistent Volume.
A hostPath Persistent Volume allows mounting files and directories on the Kubernetes Node.
This is helpful for development and testing on a single-node cluster.
Defines the Persistent Volume:
Persistent Volumes are defined in the core API group, so the apiVersion field can skip the api group.
The "spec.accessModes" field defines the access mode to the Persistent Volume (how it will be mounted): ReadWriteOnce (RWO), ReadWriteMany (RWM), ReadOnlyMany (ROM).
A Persistent Volume can be created in one access mode (you cannot combine RWO and RWM).
The Persistent Volume Claim will mount/bind the Persistent Volume with the same access mode.
-
ReadWriteOnce (RWO):
Defines a Persistent Volume with the read/write access mode and can be mounted/bound by one single Persistent Volume Claim.
If multiple Persistent Volume Claims tries to use the Persistent Volume, then only one will be bound and the remaining PVCs will be in status pending.
-
ReadWriteMany (RWM):
Defines a Persistent Volume with the read/write access mode and can be mounted/bound by multiple Persistent Volume Claims (NFS storage).
-
ReadOnlyMany (ROM):
Defines a Persistent Volume with the read only access mode and can be mounted/bound by multiple Persistent Volume Claims.
The "spec.storageClassName" field defines the name of the storage class.
The "spec.capacity.storage" field defines size of the volume (must not be larger than the size of the backend storage).
The "spec.persistentVolumeReclaimPolicy" field defines how the data will managed when the Persistent Volume Claim is deleted: Retain, Delete.
-
Retain:
Deleting the Persistent Volume Claims won't delete the associated data stored in the external storage system.
-
Delete:
Deleting the Persistent Volume Claims will also delete the associated data stored in the external storage system.
To apply the file:
View the Persistent Volume:
The "STATUS" of the Persistent Volume is "Available",
which means it has not yet been bound to a Persistent Volume Claim.