[英]Bind mount volume between host and pod containers in Kubernetes
I have a legacy application that stores some config/stats
in one of the directory on OS partition (eg /config/), and I am trying to run this as a stateful container in Kubernetes cluster. 我有一个遗留应用程序,它将一些config/stats
存储在OS分区上的目录之一(例如/ config /)中,并且我试图在Kubernetes集群中将其作为有状态容器运行。
I am able to run it as a container but due to the inherent ephemeral nature of containers, whatever data my container is writing to the OS partition directory /config/ is lost when the container goes down/destroyed. 我能够将其作为容器运行,但是由于容器固有的短暂特性,当容器发生故障/销毁时,我的容器写入OS分区目录/ config /的所有数据都会丢失。
I have the Kubernetes deployment file written in such a way that the container is brought back to life, albeit as a new instance either on same host or on another host, but this new container has no access to the data written by previous instance of the container. 我以这样的方式编写了Kubernetes部署文件,即使该容器恢复了活力,尽管它是在同一主机上或在另一主机上的新实例,但是此新容器无法访问该容器的先前实例写入的数据。容器。
If it was a docker container I could get this working using bind-mounts, so that whatever data the container writes to its OS partition directory is saved on the host directory, so that any new instance would have access to the data written by previous instance. 如果它是一个docker容器,我可以使用bind-mounts进行工作,以便将该容器写入其OS分区目录的所有数据保存在主机目录中,以便任何新实例都可以访问由先前实例写入的数据。
But I could not find any alternative for this in Kubernetes. 但是我在Kubernetes中找不到其他选择。
I could use hostpath provisioning, but hostpath-provisioning right now works only for single-node kubernetes cluster. 我可以使用主机路径置备,但是主机路径置备现在仅适用于单节点kubernetes集群。
Is there a way I could get this working in a multi-node Kubernetes cluster? 有什么办法可以使它在多节点Kubernetes集群中工作吗? Any other option other than hostpath provisioning? 除了主机路径配置之外,还有其他选择吗? I can get the containers talk to each other and sync-the data between nodes, but how do we bind-mount a host directory to container? 我可以使容器相互通信并在节点之间同步数据,但是如何将主机目录绑定安装到容器?
Thanks for your help in advance! 谢谢您的帮助!
This is what you have Volumes and VolumeMounts for in your POD definition. 这就是POD定义中要使用的Volumes和VolumeMounts。 Your lead about hostPath is the right direction, but you need a different volume type when you host data in a cluster (as you seen your self). 关于hostPath的线索是正确的方向,但是在群集中托管数据时(如您所见,您需要一个不同的卷类型)。
Take a look at https://kubernetes.io/docs/concepts/storage/volumes/ for a list of supported storage backends. 查看https://kubernetes.io/docs/concepts/storage/volumes/ ,以获取受支持的存储后端列表。 Depending on your infrastructure you might find one that suits your needs, or you might need to actually create a backing service for one (ie. NFS server, Gluster, Ceph and so on). 根据您的基础架构,您可能会找到一个适合您需求的基础架构,或者您可能需要为其中一个基础架构创建后备服务(即NFS服务器,Gluster,Ceph等)。
If you want to add another abstraction layer to make a universal manifest that can work on different environments (ie. with storage based on cloud provider, or just manualy provisioned depending on particular needs). 如果要添加另一个抽象层来制作可以在不同环境下工作的通用清单(即,基于云提供商的存储,或者仅根据特定需求手动配置)。 You will want to get familiar with PV and PVC ( https://kubernetes.io/docs/concepts/storage/persistent-volumes/ ), but as I said they are esntially an abstraction over the basic volumes, so you need to crack that first issue anyway. 您可能想熟悉PV和PVC( https://kubernetes.io/docs/concepts/storage/persistent-volumes/ ),但是正如我所说的,它们本质上是对基本卷的抽象,因此您需要破解无论如何,第一个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.