Kubernetes不会将数据复制到已安装的卷中 [英] Kubernetes not copying data into mounted Volume

查看:61
本文介绍了Kubernetes不会将数据复制到已安装的卷中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此处的文档: https://docs.docker.com/storage/volumes/

如果您如上所述启动一个容器来创建新的卷,并且该容器在要挂载的目录中有文件或目录(例如/app/以上),则目录的内容将被复制到该卷中.然后,该容器将挂载并使用该卷,其他使用该卷的容器也可以访问预先填充的内容.

If you start a container which creates a new volume, as above, and the container has files or directories in the directory to be mounted (such as /app/ above), the directory’s contents are copied into the volume. The container then mounts and uses the volume, and other containers which use the volume also have access to the pre-populated content.

换句话说,期望是,如果我在/var/lib/mysql中有这样的文件

In other words, the expectation is that, if i have files like so in /var/lib/mysql

root@d8fa9a8b305a:/var/lib/mysql# ls
auto.cnf         xtz           ib_logfile0  ibdata1  mysql               sys
debian-5.7.flag  ib_buffer_pool  ib_logfile1  ibtmp1   performance_schema

然后,当我将卷装入/var/lib/mysql时,容器中的所有文件都应复制到我的卷中.

Then, when I mount a volume into /var/lib/mysql then all the files from the container should be copied into my volume.

但是我发现这没有发生:

But I find this is not happening:

/var/lib/mysql/mysql # ls
auto.cnf        ib_buffer_pool  ib_logfile0     ib_logfile1     ibdata1

这是我安装到/var/lib/mysql中的卷的内容,并且您可以看到数据与docker映像本身的/var/lib/mysql中存在的数据不同.因此,启动失败.

This is content of the volume that I mounted into /var/lib/mysql, and as you can see the data is not the same as the one present in /var/lib/mysql of the docker image itself. So, as a result, there's a failure on startup.

注意:该卷实际上是由kubernetes挂载的.因此,我在这里做出一个主要假设

Note: The Volume in question is actually mounted by kubernetes. So, I'm making a major assumption here that

volumeMounts:
        - name: xtz-persistent-storage
          mountPath: "/var/lib/mysql/"

等同于执行此操作:docker run -p 443:443 --rm -v mysql:/var/lib/mysql <image>

推荐答案

Kubernetes Volumes与Docker Volumes不同.

Kubernetes Volumes is not the same thing as Docker Volumes.

从Kubernetes 文档:

From the Kubernetes documentation:

Docker也有卷的概念,尽管它稍微松散一些,管理起来也比较少.在Docker中,卷只是磁盘上或另一个容器中的目录.生命周期无法管理,直到最近才只有本地磁盘支持的卷. Docker现在提供了卷驱动程序,但目前的功能非常有限(例如,从Docker 1.7开始,每个容器只允许使用一个卷驱动程序,并且无法将参数传递给卷).

Docker also has a concept of volumes, though it is somewhat looser and less managed. In Docker, a volume is simply a directory on disk or in another container. Lifetimes are not managed and until very recently there were only local-disk-backed volumes. Docker now provides volume drivers, but the functionality is very limited for now (e.g. as of Docker 1.7 only one volume driver is allowed per container and there is no way to pass parameters to volumes).

另一方面,Kubernetes卷具有明确的生命周期-与包围它的Pod相同.因此,卷将超过在Pod中运行的所有容器的寿命,并且在容器重新启动后将保留数据.当然,当Pod不再存在时,其体积也将不再存在.也许比这更重要的是,Kubernetes支持多种类型的卷,并且Pod可以同时使用任意数量的卷.

A Kubernetes volume, on the other hand, has an explicit lifetime - the same as the pod that encloses it. Consequently, a volume outlives any containers that run within the Pod, and data is preserved across Container restarts. Of course, when a Pod ceases to exist, the volume will cease to exist, too. Perhaps more importantly than this, Kubernetes supports many types of volumes, and a Pod can use any number of them simultaneously.

卷的核心只是一个目录,其中可能包含一些数据,吊舱中的容器可以访问该目录.该目录的名称,支持该目录的介质以及目录的内容取决于所使用的特定卷类型.

At its core, a volume is just a directory, possibly with some data in it, which is accessible to the containers in a pod. How that directory comes to be, the medium that backs it, and the contents of it are determined by the particular volume type used.

因此,尽管概念的名称相同,但volume是不同的.

So, although the name of the concept is the same, that is a different volume.

在坐骑上,Kubernetes覆盖目标目录.

On the mount, Kubernetes overlays a destination directory.

不幸的是,到目前为止,还没有办法合并已装入的卷和容器中的内容.这是有关讨论之一.

Unfortunately, for now, there are no ways to merge the content in the mounted volume and in the container. Here is one of discussions about it.

这篇关于Kubernetes不会将数据复制到已安装的卷中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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