docker - How to mimic '--volumes-from' in Kubernetes -


i'm looking pattern allows share volumes between 2 containers running on same pod in kubernetes.

my use case is: have ruby on rails application running inside docker container. docker image contains static assets in /app/<app-name>/public directory, , need access assets nginx container running alongside in same pod.

in 'vanilla' docker have used --volumes-from flag share directory:

docker run --name app -v /app/<app-dir>/public <app-image> docker run --volumes-from app nginx 

after reading doc: https://github.com/googlecloudplatform/kubernetes/blob/master/docs/volumes.md tried (only relevant entries presented):

spec:   containers:     - image: <app-image>       name: <app-name>       volumemounts:         - mountpath: /app/<app-name>/public           name: assets     - image: nginx       name: nginx       volumemounts:         - mountpath: /var/www/html           name: assets           readonly: true     volumes:       - name: assets         hostpath:           path: /tmp/assets 

but:

  • even though /tmp/assets on node exists, it's empty
  • /app/<app-name>/public inside app container empty

as workaround i'm gonna try populate shared directory when application container (simply cp /app/<app-name>/public/* shared directory), dislike idea.

question: how mimic --volumes-from in kubernetes, or if there no direct counterpart, how can share files 1 container other running in same pod ?

apiversion: v1beta3

client version: version.info{major:"0", minor:"17", gitversion:"v0.17.0", gitcommit:"82f8bdac06ddfacf493a9ed0fedc85f5ea62ebd5", gittreestate:"clean"} server version: version.info{major:"0", minor:"17", gitversion:"v0.17.0", gitcommit:"82f8bdac06ddfacf493a9ed0fedc85f5ea62ebd5", gittreestate:"clean"} 

[update-2016-8] in latest kubernetes release, can use nice feature named init-container replace poststart part in answer below, make sure container order.

enter image description here

note: initcontainer still beta feature work version of yaml like: http://kubernetes.io/docs/user-guide/production-pods/#handling-initialization, please notice pod.beta.kubernetes.io/init-containers part.

---original answer begin---

actually, can. need use container life cycle handler control files/dirs want share other containers. like:

--- apiversion: v1 kind: pod metadata:     name: server spec:     restartpolicy: onfailure     containers:     - image: resouer/sample:v2       name: war       lifecycle:         poststart:           exec:             command:               - "cp"               - "/sample.war"               - "/app"       volumemounts:       - mountpath: /app         name: hostv1      - name: peer       image: busybox       command: ["tail", "-f", "/dev/null"]       volumemounts:       - name: hostv2         mountpath: /app/sample.war     volumes:     - name: hostv1       hostpath:           path: /tmp     - name: hostv2       hostpath:           path: /tmp/sample.war 

please check gist more details:

https://gist.github.com/resouer/378bcdaef1d9601ed6aa

and of course can use emptydir. thus, war container can share /sample.war peer container without mess peer's /app directory.

if can tolerate /app been overridden, simpler:

--- apiversion: v1 kind: pod metadata:   name: javaweb-2 spec:   restartpolicy: onfailure   containers:   - image: resouer/sample:v2     name: war     lifecycle:       poststart:         exec:           command:             - "cp"             - "/sample.war"             - "/app"     volumemounts:     - mountpath: /app       name: app-volume   - image: resouer/mytomcat:7.0     name: tomcat     command: ["sh","-c","/root/apache-tomcat-7.0.42-v2/bin/start.sh"]     volumemounts:     - mountpath: /root/apache-tomcat-7.0.42-v2/webapps       name: app-volume     ports:     - containerport: 8080       hostport: 8001    volumes:   - name: app-volume     emptydir: {} 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -