简体   繁体   English

在Kubernetes中的主机和Pod容器之间绑定挂载卷

[英]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.

相关问题 无法将卷装入 kube.netes 中的 pod - Unable to mount a volume into a pod in kubernetes 在容器之间挂载共享卷 - Mount a shared volume between containers kubernetes:在pod启动后挂载主机路径卷 - kubernetes: Mount hostpath volume after pod start 如何从使用 KubernetesPodOperator 触发它的 Airflow 主机将卷挂载到运行 docker 容器的 Kubernetes Pod - How to mount a volume to a Kubernetes Pod running a docker container from the Airflow host that triggers it using the KubernetesPodOperator Docker Compose-[link / mount volume / volume_from]在容器之间共享数据,不使用主机 - Docker Compose - [link/mount volume/volume_from] sharing data between containers, not using host 如何将气流工人的体积安装到气流kubernetes吊舱操作员上? - How to mount volume of airflow worker to airflow kubernetes pod operator? 写入卷安装时Kubernetes Pod内存不足 - Kubernetes pod running out of memory when writing to a volume mount 无法将 MySQL 数据卷挂载到 Kubernetes Minikube pod - Unable to mount MySQL data volume to Kubernetes Minikube pod WSL Kubernetes Pod 卡在 ContainerCreating state 由于卷挂载 - WSL Kubernetes Pod stuck in ContainerCreating state due to volume mount 无法在docker中的主机和容器之间挂载卷 - Unable to mount volume between host and container in docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM