Docker volume and kubernetes volume

6/10/2020

I am new to kubernetes/docker and was wondering what the docker volume configuration equivalent is in kubernetes. In the docker-compose file, you can create volumes like this:

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. (2) allows changes to all the wordpress files except wordpress/file-abc.

What is the kubernetes equivalent of (1) when creating persistent volumes in kubernetes? Are volumeMounts in Kubernetes the equivalent for (2)?

-- saragit
docker
docker-compose
kubernetes
wordpress

1 Answer

6/11/2020

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

mount now

    volumeMounts:
    - mountPath: /test-pd
      name: test-volume
-- Taybur Rahaman
Source: StackOverflow