<p>All,</p>
<p>I deployed the below yaml file and it got deployed. I'm in the process of learning about Volume, VolumeMount and MountPath.</p>
<p>I see the <strong>containerdrive</strong> folder specified in the mountpath in the container (I did a kubectl exec -it podname) and in the <strong>containerdrive</strong> I was hoping to see the files in the folder  &quot;<strong>/home/rgn/kubernetes/scripts</strong>&quot; specified in the Path of HostPath. But that is not the case and infact the containerdrive is empty.</p>
<p>Looks like my understanding of  Volume, VolumeMount and MountPath is wrong. What am I missing? Can someone point me in the right direction?</p>
<p>Thanks,
rgn</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.4
        ports:
        - containerPort: 80
        volumeMounts:
          - mountPath: /containerdrive
            name: test-volume
      volumes:
      - name: test-volume
        hostPath:
      # directory location on host
          path: /home/rgn/kubernetes/scripts
      # this field is optional
      #    type: DirectoryOrCrate
</code></pre>

Gopinath Rajee
<blockquote>
<p>Looks like my understanding of Volume, VolumeMount and MountPath is wrong. What am I missing? Can someone point me in the right direction?</p>
<pre><code>     hostPath:
   # directory location on host
       path: /home/rgn/kubernetes/scripts
</code></pre>
</blockquote>
<p>The <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath" rel="nofollow noreferrer"><code>hostPath</code></a> volume mounts a file or directory from the <strong>Kubernetes (k8s) host node's filesystem</strong> into your Pod. This is not something that most Pods will need, but it offers a powerful escape hatch for some applications.
This <code>path</code> refers to the path on k8s Node that runs your container <code>nginx</code>.</p>
<p>To answer your specific case: please ensure that directory <code>/home/rgn/kubernetes/scripts</code> exists on your k8s node.</p>
<p>I have just ran the deployment from question on my own gke cluster (2 nodes)</p>
<pre><code>$kubectl get nodes 
NAME                                         
gke-ubuntu-mnnv   
gke-ubuntu-nw9v

$ kubectl apply -f deployment.yaml


$ kubectl get pods -o wide 
NAME                               READY   STATUS    RESTARTS   AGE    NODE                                         
nginx-deployment-ddbfb785d-fggpq   1/1     Running   0          19s    gke-ubuntu-nw9v


$ kubectl exec nginx-deployment-ddbfb785d-fggpq -- ls -la containerdrive
total 8
drwxr-xr-x 2 root root 4096 Jun 22 11:54 .
drwxr-xr-x 1 root root 4096 Jun 22 11:55 ..
-rw-r--r-- 1 root root    0 Jun 22 11:54 gke-ubuntu-nw9v-file

$ kubectl describe deployments nginx-deployment 
...
    Mounts:
      /containerdrive from test-volume (rw)
  Volumes:
   test-volume:
    Type:          HostPath (bare host directory volume)
    Path:          /tmp/knp
    HostPathType:  
...

# and on k8s node itself:

$ ls -lah /tmp/knp/
total 8.0K
drwxr-xr-x  2 root root 4.0K Jun 22 11:54 .
drwxrwxrwt 10 root root 4.0K Jun 22 12:08 ..
-rw-r--r--  1 root root    0 Jun 22 11:54 gke-ubuntu-nw9v-file

</code></pre>
<p>I hope that output helps to see the whole picture clearly. :)</p>
<p>Additionally, as David Maze mentioned, it might be a good idea to compile all the scripts you rely on into the container itself.</p>
