Shared Volume In Kubernetes - Using hostPath
Since data by nature in a container doesn’t persist it is useful to be able to use a volume to allow data to persist across deployments. We wrote about this in Docker and it is a bit different in Kubernetes. Multiple pods can share a data volume and can also reattach data volumes if a pod is scheduled on a different node. In most cases the assumption is that you are using some kind of cloud provider which comes with the ability to provide the storage mechanism for a volume.
A persistent volume (PV) “is a storage resource that is created and managed by the Kubernetes API that can exist beyond the lifetime of an individual pod.” (Source - Azure Docs) A PersistentVolumeClaim is the type of StorageClass with a particular access mode, and size that is directly tied to a Persistent Volume and allows you to request the desired storage type.
Similar to our Docker example that we mentioned in the beginning, for our Kubernetes example we want to map a volume from the host node’s filesystem into a pod. As mentioned earlier we’ll need a PersistentVolume (PV) and PersistentVolumeClaim (PVC) and a pod or deployment that references the volume.