How to avoid override the container directory when using pvc in kubernetes?

江枫思渺然 提交于 2021-02-07 20:57:50

问题


When using pvc to persist the container data, it seems pvc always override the container's directory, the original data in directory will not be available, what's the reason ?


回答1:


This is by design. Kubelet is responsible for preparing the mounts for your container, and they can come from plaethora of different storagebackends. At the time of mounting they are empty and kubelet has no reason to put any content in them.

That said, there are ways to achieve what you seem to expect by using init container. In your pod you define init container using your docker image, mount your volume in it in some path (ie. /target) but instead of running regular content of your container, run something like

cp -r /my/dir/* /target/ 

which will initiate your directory with expected content and exit allowing further startup of the pod



来源:https://stackoverflow.com/questions/51739517/how-to-avoid-override-the-container-directory-when-using-pvc-in-kubernetes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!