hostPath deployment.yaml


#1

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


#2

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


#3

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.


#4

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?


#5

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 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 for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:


#6

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).


#7

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.


#8

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?


#9

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


#10

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.


#11

Not a problem here is some documentation on how to create a configmap and mount it into a pod and another showing how to configure Redis using a configmap.

Hopefully that helps.

Let me know if if it works


#12

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.


#13

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.


#14

+1. Please try this and share :slight_smile:


#15

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 …


#16

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


#17

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.