Hello, everyone. i hope everything is fine. i have a question about HostPath typ . . .

mk:
hello, everyone.
i hope everything is fine.
i have a question about HostPath type of volumes.
so in the doc it says A hostPath volume mounts a file or directory from the host node's filesystem into your Pod
here is the link: <https://kubernetes.io/docs/concepts/storage/volumes/#hostpath>

so, when i was creating this pv:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-httpd-webroot
spec:
  capacity:
    storage: 64Mi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  hostPath:
    path: "/mnt/data"

i was expecting the pod that will claim this, would save everything under the node host “/mnt/data”

but once i’ve deployed and create a file, i’ve checked under that path and ther was nothing:

# tree mnt/
mnt/

0 directories, 0 files

so i was woundering that which path actually is being used by this statement?:

  hostPath:
    path: "/mnt/data"

thanks a lot for your help! :smile:

Adarsh Nair:
if you want directory or file to get created during volume create use DirectoryOrCreate or FileOrCreate

mk:
@Adarsh Nair thanks for the reply.
ok, but i’ve tested in this way:

- Exec a command in either of the httpd containers and create a blank file /usr/local/apache2/htdocs/blank.html.
- Delete the deployment object httpd-persistent.
- Create the deployment object httpd-persistent again.
- Exec a command in either of the httpd containers to verify that the file /usr/local/apache2/htdocs/blank.html exists.

even if the directory on node host wasn’t created, the file that i’ve created exists, even after i’ve recreated it.

so i want to understand then, where it was stored ?