Kubernetes persistent volume mount point path access

7/20/2018

I have created one Persistent volume in GCP k8s cluster

kind: PersistentVolume
apiVersion: v1
metadata:
 name: test
 labels:
  type: local
spec:
 storageClassName: manual
 capacity:
  storage: 1Gi
 accessModes:
  - ReadWriteOnce
 hostPath:
  path: "/mnt/xyz"

I would like understand the path "/mnt/xyz" is taking from ? I have checked the cluster nodes , didn't find the path "/mnt/xyz".
Can anyone please enlighten me on this. Thanks in advance.

-- Rajib Mitra
google-cloud-platform
google-kubernetes-engine
kubernetes

1 Answer

7/21/2018

Can anyone please enlighten me on this.

You can find a nice description of ‘hostPath’ in the official documentation. For some quick pointers:

  • since you didn’t specify optional type, it will be mounted without path existence checks, (and also won’t auto create path for you, see next point).
  • on every node that your pod can run you need to have ‘/mnt/xyz’ path created, since your type is undefined.
  • if your pod can be run on different nodes you can (and most probably will) end up with different content of that path on different nodes (they are not synced between nodes but are local to each node) unless you tie pod to specific node to make sure it always has same hostPath content.

In your case you have to create /mnt/xyz on each node, start pod, check on which node pod started and observe /mnt/xyz on that specific node get used by pod. Now, once you restart pod and if it gets rescheduled to another node you will see that on previous node state of /mnt/xyz is frozen at the moment first pod stopped running and on newly allocated node it is reinitialized to initial state and gets used.

-- Const
Source: StackOverflow