简体   繁体   English

Docker 卷和 kubernetes 卷

[英]Docker volume and kubernetes volume

I am new to kubernetes/docker and was wondering what the docker volume configuration equivalent is in kubernetes.我是 kubernetes/docker 的新手,想知道 docker 卷配置等效项在 kubernetes 中是什么。 In the docker-compose file, you can create volumes like this:在 docker-compose 文件中,您可以像这样创建卷:

volumes:
   - wordpress/file-abc (1)
   - wordpress:/var/www/html (2)

(1) tells docker to keep the content within wordpress/file-abc unchanged if there is a change in /var/www/html. (1) 告诉 docker 如果 /var/www/html 发生变化,则保持wordpress/file-abc中的内容不变。 (2) allows changes to all the wordpress files except wordpress/file-abc . (2) 允许更改除wordpress/file-abc之外的所有 wordpress 文件。

What is the kubernetes equivalent of (1) when creating persistent volumes in kubernetes?在 kubernetes 中创建持久卷时,与 (1) 等效的 kubernetes 是什么? Are volumeMounts in Kubernetes the equivalent for (2)? Kubernetes 中的 volumeMounts 是否等同于 (2)?

In Docker, Actually, volume is managed by docker using three way, 1.volume 2.Bind mount 3.tmpfs.在 Docker 中,实际上卷是由 docker 使用三种方式管理的,1.volume 2.Bind mount 3.tmpfs。

# volume: when you use -v and --volume in docker without referencing the full or relative path on the host machine then docker will create volume which is new directory and its is created within Docker's storage directory on the host machine, and Docker manages that directory's contents. # 卷:当你在 docker 中使用 -v 和 --volume 而不引用主机上的完整或相对路径时,docker 将创建卷,这是一个新目录,它是在主机上的 Docker 存储目录中创建的,并且 ZC5CFD27222EBA43B该目录的内容。

# Bind mount: when you use -v or --volume with the file or directory which is referenced by its full or relative path on the host machine then docker will just map the that host machine directory with the mentioned container directory. # 绑定挂载:当您使用 -v 或 --volume 与主机上的完整或相对路径引用的文件或目录时,docker 将只是 map 带有提到的容器目录的主机目录。

#tmpfs: When you create a container with a tmpfs mount, the container can create files outside the container's writable layer.for more detail see this document . #tmpfs:当你创建一个带有 tmpfs 挂载的容器时,容器可以在容器的可写层之外创建文件。更多详细信息请参阅此文档

In Kubernetes: Volume is not only restricted to a directory on disk.在 Kubernetes 中:卷不仅限于磁盘上的目录。 You can create a different type of volume in different filesystem.您可以在不同的文件系统中创建不同类型的卷。 you can get the details supported volume here .您可以在此处获取支持的详细信息。 You can compare docker bind mount with Kubernetes volume type hostpath.see details here .您可以将 docker 绑定挂载与 Kubernetes 卷类型主机路径进行比较。请参阅 此处的详细信息。

The answer of when creating persistent volumes in kubernetes?在 kubernetes 中创建持久卷时的答案?

when you need to have your data persistent across container, you can create presistant volume using any volume type.当您需要跨容器持久保存数据时,您可以使用任何卷类型创建抗性卷。

Are volumeMounts in Kubernetes the equivalent for (2)? Kubernetes 中的 volumeMounts 是否等同于 (2)?

NO,volumeMounts is used in kubernetes to mount a volume that is created by a any volume type.不,volumeMounts 在 kubernetes 中用于挂载由任何卷类型创建的卷。 for example:例如:

volumes:
  - name: test-volume
    # This GCE PD must already exist.
    gcePersistentDisk:
      pdName: my-data-disk
      fsType: ext4

mount now立即安装

    volumeMounts:
    - mountPath: /test-pd
      name: test-volume

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM