Kubernetes Volume mountpath

839 views
Skip to first unread message

Montassar Dridi

unread,
Mar 1, 2017, 2:28:42 PM3/1/17
to Kubernetes developer/contributor discussion
I'm running multiple web pods for the same application and I have this folder in my application where clients can upload their files.
the folder is sitting in this directory  /usr/local/tomcat/webapps/ROOT/uploadfiles and I want it to be shared between all the web pods, 
in case the client login to a random session within a specific web POD 1 and upload some files there, can find them next time he logs in to another random session within another web POD N 
I'm using Google Cloud Platform container engine and Google persistent disk as persistent volume
my web application Dockerfile for my image and DEPLOYMENT YAML files looks something like this 

FROM tomcat:8-jre8
ADD ROOT.war /usr/local/tomcat/webapps/
CMD ["catalina.sh", "run"]
---------------------------------------
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: web-pv-claim
  labels:
    name: web-pod
    version: v1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
------------------
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: web-dp
  labels:
    name: web-pod
    version: v1
spec:
      containers:
      - image: gcr.io/projectid/demo:v1
        name: web-pod
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: persistent-storage
          mountPath: /usr/local/tomcat/webapps
     ports:
        - containerPort: 8080
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: web-pv-claim

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


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 also when i mountpath to a different directory like for example /sample then /usr/local/tomcat/webapps and /sample will have the same exact folders and files !!! and when I upload a file I only see it in the /usr/local/tomcat/webapps/ROOT/uploadefiles inside a specific pod and not shared to the other pods

Saad Ali

unread,
Mar 1, 2017, 2:42:52 PM3/1/17
to Montassar Dridi, Kubernetes developer/contributor discussion
When you mount your volume into a path that already the existing content of that folder will be hidden. So in this case the existing contents of your container at "/usr/local/tomcat/webapps/" gets replaced with the contents of your PV that you mount to "/usr/local/tomcat/webapps".

Mounting your volume data to a different path is the correct thing to do, but you need to realize that the shared path is not  "/usr/local/tomcat/webapps/" but is the path you mount to, e.g. "/sample". 

> when i mountpath to a different directory like for example /sample then /usr/local/tomcat/webapps and /sample will have the same exact folders and files

This is probably because you have identical content (a copy) in your container and on your PV.

> when I upload a file I only see it in the "/usr/local/tomcat/webapps/ROOT/uploadefiles" inside a specific pod and not shared to the other pods

Your application needs to be updated to write data to the shared folder PV folder (e.g. "/sample"). It appears that by default it uploads the contents to "/usr/local/tomcat/webapps/ROOT/uploadfiles" which (if your PV is mounted to "/sample") is local to the container (not shared).

If you can't change the folder that your application writes the uploaded files to. You can mount your PV directly to "/usr/local/tomcat/webapps/ROOT/uploadfiles" instead of "/usr/local/tomcat/webapps/", assuming that path contains no data initially.



--
You received this message because you are subscribed to the Google Groups "Kubernetes developer/contributor discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-dev+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-dev@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/e04890e0-278b-41b1-9e8c-589ead8d8178%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Montassar Dridi

unread,
Mar 1, 2017, 3:16:21 PM3/1/17
to Kubernetes developer/contributor discussion, montass...@gmail.com
If you can't change the folder that your application writes the uploaded files to. You can mount your PV directly to "/usr/local/tomcat/webapps/ROOT/uploadfiles" instead of "/usr/local/tomcat/webapps/", assuming that path contains no data initially.
I tried that and "/usr/local/tomcat/webapps/ROOT/uploadfiles"  has the same folders and files as "/usr/local/tomcat/webapps/  !!
same issue as the one discribed below:
> when i mountpath to a different directory like for example /sample then /usr/local/tomcat/webapps and /sample will have the same exact folders and files
This is probably because you have identical content (a copy) in your container and on your PV.
Can you explain this point more
or if you have time can we chat I'll share my screen so you get a better idea of the problem
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.

Montassar Dridi

unread,
Mar 1, 2017, 4:06:34 PM3/1/17
to Kubernetes developer/contributor discussion, montass...@gmail.com
I delete the persistent disk and created another one 
now the "/usr/local/tomcat/webapps/ROOT/uploadfiles" is empty and has only lost+found

Montassar Dridi

unread,
Mar 1, 2017, 5:49:05 PM3/1/17
to Kubernetes developer/contributor discussion, montass...@gmail.com
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 

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
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages