A hostPath Volume mounts a directory on the pod's filesystem so that its containers can have access to a storage space.
Below is a Yaml file of a pod with a hostPath type of storage:
The "/home/albert" directory from the host is mounted on the "/hostpath_dir" mountpoint of the debian container.
The "path" specifies the directory/file that will be mounted on the container's mountpoint "/hostpath_dir".
The "type" could be -DirectoryOrCreate - which means that the directory will be created if it doesn't exist on the host, or - Directory - which means that the directory must be present on the host otherwise, we will get an error at the creation of the pod.
There are other types like - File, Socket, CharDevice, BlockDevice, ... -
We could check our pod using the below command:
Then we check its volume - storage - using the below command:
We could access our volume "volume-1" as below:
To mitigate the security risks related to the "hostPath" volumes, we could use it as "read-only" as you can see below in the "volumeMounts" section of the container: