How to mount volume into the source code of the ap

2019-07-15 05:16发布

I have kubernetes pod where I am mounting my app source code as git volume. I tried various setups for how to put the source code into the pod and git volume was the one I ended up with in the end.

But now I have an issue with data. My app has a files directory in it(empty) and I need to mount a volume(fuse) in there. But since the destination is located on the git volume I cannot do this. So I am wondering how should I redesign my app?

Should I build the app's source code directly into the image so that I can then mount the data volume into it or is there some way I can mount volume into another so that I do not have to adjust anything?

I cannot move the target directory elsewhere since it has to be accessible by the app in its directory and also from web.

1条回答
何必那么认真
2楼-- · 2019-07-15 06:02

What I usually do is add the sources to the docker image when building the image. This is a straight forward process and you can always see the images as a black box in terms of deployment. What this achieves is effectively decoupling the preparation of the image and deploying/updating at run time as two different processes.

I believe this is the reason why kubernetes makes it easy to perform rolling upgrades for rolling out new software versions by exchanging a complete image, rather than trying to fix up the contents of a container. It is as easy as using the following command:

kubectl set image deployment/my-nginx-deployment my-nginx-image=TagXX

Replacing images also ensures that any debris is cleaned up (e.g. growing logs, temporary files etc.) and it allows you to bring along way more changes instead of just changing sources (e.g. upgrading server software versions).

It also allows you to perform testing/staging based on the exact images and not only a code deployment on servers that may not be identical to production servers.

You can read up on it at this page under Updating a Deployment.

查看更多
登录 后发表回答