# hostPath deployment.yaml

**URL:** <https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172>\
**Category:** General Discussions\
**Created:** [March 2, 2019, 5:02am UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172 "2019-03-02T05:02:01Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 2, 2019, 5:02am UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/1 "2019-03-02T05:02:01Z")

</div>

Hello everyone,

I’m playing with Kubernates and I have problems to mount a local folder to the deployment made, If I do a describe pod I will see the mounted drive there, but if I go into one of the pods it’s empty it doesn’t show me the content of the local folder. What am I doing wrong?

Thanks

---

<div class="post-metadata">

**Author:** ![rata](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/rata/32/18244_2.png) [@rata](https://discuss.kubernetes.io/u/rata)\
**Post date:** [March 2, 2019, 5:54am UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/2 "2019-03-02T05:54:17Z")

</div>

Are you defining the volume AND the mount point in the yaml? Can you share your deployment? 🙂

---

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 2, 2019, 2:43pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/3 "2019-03-02T14:43:42Z")

</div>

Hello, Rodrigo thanks for your quick response here the deployment.yaml that I’m using

#-  
apiVersion: apps/v1  
kind: Deployment  
metadata:  
name: the-name  
labels:  
app: nginx  
spec:  
replicas: 3  
selector:  
matchLabels:  
app: nginx  
template:  
metadata:  
labels:  
app: nginx  
spec:  
containers:  
- name: the-name  
image: nginx  
ports:  
- containerPort: 80  
volumeMounts:  
# - name: nginx-conf  
# mountPath: /etc/nginx/conf.d/default.conf  
# subPath: default.conf  
- name: landingpage  
mountPath: /usr/share/nginx/html  
restartPolicy: Always  
volumes:  
# - name: nginx-conf  
# hostPath:  
# path: /my/path/to/nginx/conf.d  
- name: landingpage  
hostPath:  
path: /the/path/to/landing-page

# -

The deployment working fine, I can see the nginx default “hello world”, but I want my landing page to show and to use my nginx.conf file.

Thanks for all your help.

---

<div class="post-metadata">

**Author:** ![rata](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/rata/32/18244_2.png) [@rata](https://discuss.kubernetes.io/u/rata)\
**Post date:** [March 2, 2019, 3:53pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/4 "2019-03-02T15:53:20Z")

</div>

So, it doesn’t show the files and describe of any pods/deployments doesn’t show errors?

And if you connect to the pod, the file is not there or it is not changing the nginx configuration but maybe the file is there?

---

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 2, 2019, 4:38pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/5 "2019-03-02T16:38:09Z")

</div>

It’s just not there, if you review the deployment.yaml, for now, I just mount the landingpage folder, so if I go -it podname – /bin/bash and cd into the path /usr/share/nginx/html it shows me nothing. I’m out of options, below the describe pods.

Name: web-prd-gscsite-com-fcc968bcc-r6smd  
Namespace: prod-gscsite-com  
Priority: 0  
PriorityClassName:   
Node: metaIp/ip  
Start Time: Sat, 02 Mar 2019 15:22:13 +0000  
Labels: app=nginx  
pod-template-hash=fcc968bcc  
Annotations:   
Status: Running  
IP: yes is a IP  
Controlled By: ReplicaSet/web-prd-gscsite-com-fcc968bcc  
Containers:  
web-prd-gscsite-com:  
Container ID: docker://27610e5e43a309adaa7a63d4e44dc40be7cbb742cfb6d5eebea73646c61c2182  
Image: nginx  
Image ID: docker-pullable://nginx@sha256:18c0755594af107923baa2e65fcef35aea4ab0cea7862d19c27aa127bacb458e  
Port: 80/TCP  
Host Port: 0/TCP  
State: Running  
Started: Sat, 02 Mar 2019 15:22:14 +0000  
Ready: True  
Restart Count: 0  
Environment:   
Mounts:  
/usr/share/nginx/html from landingpage (ro)  
/var/run/secrets/[kubernetes.io/serviceaccount](http://kubernetes.io/serviceaccount) from default-token-vqdzp (ro)  
Conditions:  
Type Status  
Initialized True  
Ready True  
ContainersReady True  
PodScheduled True  
Volumes:  
landingpage:  
Type: HostPath (bare host directory volume)  
Path: /the/path/of/my/landing-page  
HostPathType:  
default-token-vqdzp:  
Type: Secret (a volume populated by a Secret)  
SecretName: default-token-vqdzp  
Optional: false  
QoS Class: BestEffort  
Node-Selectors:   
Tolerations: [node.kubernetes.io/not-ready:NoExecute](http://node.kubernetes.io/not-ready:NoExecute) for 300s  
[node.kubernetes.io/unreachable:NoExecute](http://node.kubernetes.io/unreachable:NoExecute) for 300s  
Events:

---

<div class="post-metadata">

**Author:** ![rata](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/rata/32/18244_2.png) [@rata](https://discuss.kubernetes.io/u/rata)\
**Post date:** [March 2, 2019, 8:08pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/6 "2019-03-02T20:08:20Z")

</div>

Sorry, the deployment yaml is not showing correctly on my phone. Why are you using subpath? Or is it me not seeing it correctly only?

Can you try not using subpath (I understand you don’t need it, and in any case to have more info it’s good to know if works without it, to know where to continue debugging).

I don’t think I’ll have time today, but maybe in the next few days I can try it myself.

My guess now it’s maybe related to subpath or that the particular host directory that you are using is not allowed by default by kubernetes to be exposed to pods or something like that (but it’s weird to nor see errors in that case).

---

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 3, 2019, 4:01am UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/7 "2019-03-03T04:01:55Z")

</div>

Hey,

Yes, those line related to subpath are commented and yes I don’t know why I can see the content of the mount path on the pods. I have been reading and searching for answers and I found some information about storage class, so if I go, kubectl get sc --all-namespaces it says “No resources found”, so I thought if I create a local sc and try to see if it works, but my nods are complaining that they don’t have access to it so I drop it. I out of options here I really don’t know what to do or how to solve this so please I really appreciate all your help.

Thank you.

---

<div class="post-metadata">

**Author:** ![thockin](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/thockin/32/2457_2.png) [@thockin](https://discuss.kubernetes.io/u/thockin)\
**Post date:** [March 3, 2019, 5:27am UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/8 "2019-03-03T05:27:48Z")

</div>

And if you SSH into the node and `ls /the/path/to/landing-page` you say there are files there? Can you make a complete reproduction case that we can run, e.g. using nginx and /tmp or something similar?

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 3, 2019, 1:08pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/9 "2019-03-03T13:08:12Z")

</div>

Have you tried adding the nginx file as a configmap or secret and mounting that at the desired path?

---

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 3, 2019, 1:23pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/10 "2019-03-03T13:23:07Z")

</div>

No I haven’t, I really don’t know how to, if you have a link or something like that can help me I will really appreciate, as I said before I’m running out of options here.

Thanks.

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 3, 2019, 1:34pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/11 "2019-03-03T13:34:59Z")

</div>

Not a problem here is some [documentation](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) on how to create a configmap and mount it into a pod and another showing how to [configure](https://kubernetes.io/docs/tutorials/configuration/) Redis using a configmap.

Hopefully that helps.

Let me know if if it works

---

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 3, 2019, 1:54pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/12 "2019-03-03T13:54:54Z")

</div>

Thanks,

Question, so defining a pod or deployment on the yaml, what’s the difference between?, I’m using deployment and service yaml’s and works for me, but it’s the best practice?, it’s OK to use it like that?

Thanks.

---

<div class="post-metadata">

**Author:** ![macintoshprime](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/macintoshprime/32/7121_2.png) [@macintoshprime](https://discuss.kubernetes.io/u/macintoshprime)\
**Post date:** [March 3, 2019, 1:59pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/13 "2019-03-03T13:59:58Z")

</div>

In the deployment yaml you are defining a pod in the template section. The big difference between going with a deployment spec vs a pod spec is that deployments consist of one of more pods and allow you to handle scaling, rollbacks, updates, for the pods whereas a pod is just a single instance.

In most cases you’ll be using a deployment unless you have a need for a one off pod sometime.

---

<div class="post-metadata">

**Author:** ![rata](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/rata/32/18244_2.png) [@rata](https://discuss.kubernetes.io/u/rata)\
**Post date:** [March 4, 2019, 12:32am UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/14 "2019-03-04T00:32:48Z")

</div>

+1. Please try this and share 🙂

---

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 4, 2019, 3:14am UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/15 "2019-03-04T03:14:50Z")

</div>

Helle there,

Before I start I will like to say THANKS to all of you trying to help with this, THANK YOU I really appreciate it.

So far I found that some way/how the partition correctly being mounted, I try commenting my volumes in the yaml file and inspecting in one of the pods I can see the local nginx index and if I curl I I’ll be able to see the default hello world of nginx. So adding back the lines to mount my landing-page folder and inspecting into the pod the folder is empty, so it’s doing the job but for some reason, the content is not showing. here the output.

Landing page content on my host side

/landing-page/  
total 20  
drwxrwxr-x 4 ubuntu ubuntu 4096 Feb 22 04:36 .  
drwxr-xr-x 6 root root 4096 Feb 22 04:35 …  
drwxrwxr-x 8 ubuntu ubuntu 4096 Feb 17 04:16 .git  
drwxrwxr-x 2 ubuntu ubuntu 4096 Feb 17 04:16 images  
-rwxrwxr-x 1 ubuntu ubuntu 3698 Feb 17 04:16 index.html

Pods running

kubectl get pods  
NAME READY STATUS RESTARTS AGE  
web-7b5c48fd78-fmpfp 1/1 Running 0 21m  
web-7b5c48fd78-shk6p 1/1 Running 0 21m  
web-7b5c48fd78-w6gn8 1/1 Running 0 21m

into one pod

kubectl exec -it web-7b5c48fd78-fmpfp – /bin/bash

ls -la /usr/share/nginx/html/  
total 16  
drwxr-xr-x 2 root root 4096 Feb 27 23:23 .  
drwxr-xr-x 3 root root 4096 Feb 27 23:23 …  
-rw-r–r-- 1 root root 494 Feb 26 14:13 50x.html  
-rw-r–r-- 1 root root 612 Feb 26 14:13 index.html  
root@web-7b5c48fd78-fmpfp:/#

That content above is with my mount volume commented on the yaml file.

Now with my mount volume, i’m getting nothing

ls -la /usr/share/nginx/html/  
total 8  
drwxr-xr-x 2 root root 4096 Mar 2 03:53 .  
drwxr-xr-x 3 root root 4096 Feb 27 23:23 …

---

<div class="post-metadata">

**Author:** ![rata](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/rata/32/18244_2.png) [@rata](https://discuss.kubernetes.io/u/rata)\
**Post date:** [March 4, 2019, 6:12pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/16 "2019-03-04T18:12:23Z")

</div>

Would you mind doing it, as Tim said, with a public image and share the deployment and steps you do? (Probably use a dummy file in /tmp in the host to see in the pod)

So it’s easy to reproduce

---

<div class="post-metadata">

**Author:** ![kickfliph](https://avatars.discourse-cdn.com/v4/letter/k/7ba0ec/32.png) [@kickfliph](https://discuss.kubernetes.io/u/kickfliph)\
**Post date:** [March 4, 2019, 6:26pm UTC](https://discuss.kubernetes.io/t/hostpath-deployment-yaml/5172/17 "2019-03-04T18:26:42Z")

</div>

So I found the problem, I define 3 replication on my deployment file, so if you want to have consistent information across your cluster all nodes has to have the same mount point, So I scale down to 1 replica and now I’m able to see my landing page finally.

Thanks again for all your help.
