Kubernetes Volume mountpath

954 views
Skip to first unread message

Montassar Dridi

unread,
Feb 28, 2017, 8:14:41 PM2/28/17
to Kubernetes user discussion and Q&A
Hello!!
The Dockerfile for my web application image, that I deployed within Kubernetes, looks like this :
FROM tomcat:8-jre8
ADD sample.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]

It works fine without volumes!!
But when I try something like the script below, so I can include volumes, my website doesn't load :
spec:
      containers:
      - image: gcr.io/projectid/demo:v1
        name: web-pod
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: persistent-storage
          mountPath: /usr/local/tomcat/webapps
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: web-pv-claim

I just wanna share a folder between my web pods ?!?!

Tim Hockin

unread,
Feb 28, 2017, 8:19:42 PM2/28/17
to kubernet...@googlegroups.com
Not enough information: What cloud environment? What does the PV
claim object look like? What does "doesn't load" mean?
> --
> You received this message because you are subscribed to the Google Groups
> "Kubernetes user discussion and Q&A" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kubernetes-use...@googlegroups.com.
> To post to this group, send email to kubernet...@googlegroups.com.
> Visit this group at https://groups.google.com/group/kubernetes-users.
> For more options, visit https://groups.google.com/d/optout.

Rodrigo Campos

unread,
Feb 28, 2017, 8:24:22 PM2/28/17
to 'Tim Hockin' via Kubernetes user discussion and Q&A
Also, if you just want to share a folder, you can use an emptyDir. It really
depends on what you want, what you should use. But as Tim says, more info is
definitely needed to *try* to help.

Please make sure to see log messages, read docs, etc. And then, if not working,
ask again with a more clear picture. Without a single error shown, not even the
claims, cloud provider, etc. is really hard to help :-(

Montassar Dridi

unread,
Feb 28, 2017, 8:45:19 PM2/28/17
to Kubernetes user discussion and Q&A
I'm using Google Cloud Platform container engine and Google persistent disk as persistent volume
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: web-pv-claim
  labels:
    name: web-pod
    version: v1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
------------------
spec:
      containers:
      - image: gcr.io/projectid/demo:v1
        name: web-pod
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: persistent-storage
          mountPath: /usr/local/tomcat/webapps
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: web-pv-claim
volumes:
      - name: web-persistent-storage
        persistentVolumeClaim:
          claimName: web-pv-claim

I get this error from the browser

This  page can’t be found

No webpage was found for the web address: https://35.185.13.141/

HTTP ERROR 404

Montassar Dridi

unread,
Feb 28, 2017, 9:24:43 PM2/28/17
to Kubernetes user discussion and Q&A
I used the emptyDir...get the same error 

Rodrigo Campos

unread,
Feb 28, 2017, 9:35:19 PM2/28/17
to kubernet...@googlegroups.com
But what is the error kubernetes shows in kubectl pod describe? What about the containers logs? Etc. This is a crucial part, nothing can't really be said without it.

Also, as a general guidance, try to isolate the problem. Maybe try running an example for using volumes (that maybe use a public docker image), to understand how to use them first. Also, you may want to run just a sleep or something and connect to the pod and see what's there, etc.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.

Montassar Dridi

unread,
Feb 28, 2017, 9:44:12 PM2/28/17
to Kubernetes user discussion and Q&A
No errors is showing in the log pods !!!
I used the same volume structure for MYSQL database and was able to share any file in var/lib/mysql directory between the database pods with no issue 

Tim Hockin

unread,
Feb 28, 2017, 11:30:58 PM2/28/17
to kubernet...@googlegroups.com
If you mount an empty dir (be that a new PD or an emptyDir) you will,
in fact, have an empty directory - which would give you exactly what
you're seeing, wouldn't it?

On Tue, Feb 28, 2017 at 6:44 PM, Montassar Dridi

Montassar Dridi

unread,
Feb 28, 2017, 11:37:50 PM2/28/17
to Kubernetes user discussion and Q&A
right !! I got an empty directory !!
so what should i do ?

Tim Hockin

unread,
Feb 28, 2017, 11:43:50 PM2/28/17
to kubernet...@googlegroups.com
Put some stuff in that directory? Where is the content coming from?
How do you expect it to end up in that directory?

On Tue, Feb 28, 2017 at 8:37 PM, Montassar Dridi

Montassar Dridi

unread,
Feb 28, 2017, 11:54:19 PM2/28/17
to Kubernetes user discussion and Q&A
I thought i did when I created the Dockerfile for the web application docker image that I pushed to the google container registry and then listed it in my web application kubernetes depolyment yaml file :

FROM tomcat:8-jre8
ADD sample.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
--------------------------
spec:
      containers:
        name: web-pod
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: persistent-storage
          mountPath: /usr/local/tomcat/webapps
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: web-pv-claim

Rodrigo Campos

unread,
Feb 28, 2017, 11:59:14 PM2/28/17
to kubernet...@googlegroups.com
Then your are mounting the volume where your war file is.

Then, as mount works (nothing special about containers), you lose visibility of the war file and now see your volume. 

That will never work.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.

Montassar Dridi

unread,
Mar 1, 2017, 12:04:39 AM3/1/17
to Kubernetes user discussion and Q&A
so I should add the war file after the mount , no need for the Dockerfile at the beginning 

Tim Hockin

unread,
Mar 1, 2017, 12:22:42 AM3/1/17
to kubernet...@googlegroups.com
Yeah, I'm trying to figure out what you are trying to achieve with a
volume? Volumes don't share files that already exist, they are a
place to put files. So you can copy it from somewhere in your image
to that shared dir, or get it from git or something...

On Tue, Feb 28, 2017 at 9:04 PM, Montassar Dridi

Montassar Dridi

unread,
Mar 1, 2017, 12:36:20 AM3/1/17
to Kubernetes user discussion and Q&A
I'm running multiple web pods for the same application and I have this folder where clients can upload their files.
So I want that folder in this directory  /usr/local/tomcat/webapps/ROOT/uploadfiles to be shared between all the web pods, 
in case the client login to a random session within a specific web POD1 and upload some files there, can find them next time he logs in to another random session within another web POD2 

Tim Hockin

unread,
Mar 1, 2017, 2:58:43 AM3/1/17
to kubernet...@googlegroups.com
You can't multi-mount any volume that models as a block device,
including GCE PD. It just isn't supported by any filesystems in
common use. Unless you have something like NFS or gluster, this won't
work.

On Tue, Feb 28, 2017 at 9:36 PM, Montassar Dridi

Montassar Dridi

unread,
Mar 1, 2017, 12:20:47 PM3/1/17
to Kubernetes user discussion and Q&A
that make sense 
can you explain this to me and sorry for taking this long I'm just little bit confused and thanks for your help and appreciate your patience

when I mountpath this directory /usr/local/tomcat/webapps I don't get an empty directory and can see all my subdirectories, folders and files inside it but I get this error 

HTTP Status 404 - /monta

type Status report

message /monta

description The requested resource is not available.


Apache Tomcat/8.0.41


But like you said before when I mountpath this directory /usr/local/tomcat/webapps/monta i get an empty monta directory !!!

So why do i get that error since /usr/local/tomcat/webapps has all the necessary subdirectories, folders and files.

Show you again my scripts
FROM tomcat:8-jre8
ADD monta.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
--------------------------
spec:
      containers:
        name: web-pod
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: persistent-storage
          mountPath: /usr/local/tomcat/webapps
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: web-pv-claim

Tim Hockin

unread,
Mar 1, 2017, 12:41:00 PM3/1/17
to kubernet...@googlegroups.com
Truthfully, I don't know enough about tomcat - with nginx or apache, I
would expect a 404 if you don't have an index.html, for example.

Rodrigo Campos

unread,
Mar 1, 2017, 12:45:27 PM3/1/17
to kubernet...@googlegroups.com
If When using no volumes your app returns 404, then is something in your app. You can try to run the container locally.

But really nothing else we can do, if the app doesn't work as expected just when running the container, you need to understand the app layer and see why it doesn't do what you expect.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.

Tim Hockin

unread,
Mar 1, 2017, 12:49:31 PM3/1/17
to kubernet...@googlegroups.com
I find that `kubectl exec`ing in and poking around often illuminates
why it didn't do what I expected. E.g. permissions (if docker makes a
dir they can be wrong, for example).

Montassar Dridi

unread,
Mar 1, 2017, 12:52:41 PM3/1/17
to Kubernetes user discussion and Q&A
it's the same war file, my application worked fine without volume but as soon as I mountpath: /usr/local/tomcat/webapps I get that error even though all the subdirectories are there not empty and have all their folders and files but but when i mountpath to a subdirectory in /usr/local/tomcat/webapps it becomes empty
again thanks for your help

Tim Hockin

unread,
Mar 1, 2017, 1:12:48 PM3/1/17
to kubernet...@googlegroups.com
you have to look at your logs or something. If you're saying the
files are identical in both cases, then I don't have a starting place.

Montassar Dridi

unread,
Mar 1, 2017, 5:48:15 PM3/1/17
to Kubernetes user discussion and Q&A
I followed this two link :
http://svblog.francedev.com/post/tutorial-kubernetes-java-tomcat-cloudsql-part1/

that's why I got same files in /usr/local/tomcat/webapps/  and any other directory 

but when I deleted the the persistent disk and created a new one 
like you guys said I get an empty directory 

so i think the best solution is to edit my application and upload the files in a directory outside of /usr/local/tomcat/webapps/
Reply all
Reply to author
Forward
0 new messages