Docker 卷和 kubernetes 卷

sar*_*git 1 wordpress docker kubernetes docker-compose

我是 kubernetes/docker 的新手,想知道 kubernetes 中的 docker 卷配置等价物是什么。在 docker-compose 文件中,您可以像这样创建卷:

volumes:
   - wordpress/file-abc (1)
   - wordpress:/var/www/html (2)
Run Code Online (Sandbox Code Playgroud)

(1)wordpress/file-abc如果 /var/www/html 发生变化,告诉 docker 保持内容不变。(2) 允许更改除wordpress/file-abc.

在 kubernetes 中创建持久卷时,kubernetes 与 (1) 的等价物是什么?Kubernetes 中的 volumeMounts 是否等同于 (2)?

Tay*_*man 5

In Docker, Actually, volume is managed by docker using three way, 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.

# 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.

#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.

In Kubernetes: Volume is not only restricted to a directory on disk. 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.

The answer of when creating persistent volumes in 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)?

NO,volumeMounts is used in kubernetes to mount a volume that is created by a any volume type. for example:

volumes:
  - name: test-volume
    # This GCE PD must already exist.
    gcePersistentDisk:
      pdName: my-data-disk
      fsType: ext4
Run Code Online (Sandbox Code Playgroud)

mount now

    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
Run Code Online (Sandbox Code Playgroud)