在kubernetes中使用pvc时如何避免覆盖容器目录? [英] How to avoid override the container directory when using pvc in kubernetes?

查看:215
本文介绍了在kubernetes中使用pvc时如何避免覆盖容器目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用pvc保留容器数据时,pvc似乎总是覆盖容器的目录,目录中的原始数据将不可用,这是什么原因?

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 ?

推荐答案

这是设计使然. Kubelet负责为您的容器准备支架,它们可以来自不同存储后端的支架.在安装时,它们是空的,并且kubelet没有理由在其中放入任何内容.

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.

也就是说,有一些方法可以通过使用init容器来实现您期望的目标.在您的Pod中,您可以使用docker映像定义init容器,在某个路径(即/target )中将卷装入其中,但不要运行容器的常规内容,而应运行

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/ 

这将使用预期的内容启动您的目录,然后退出以继续启动Pod

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

这篇关于在kubernetes中使用pvc时如何避免覆盖容器目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆