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)?
In Docker, Actually, volume is managed by docker using three way, 1.volume 2.Bind mount 3.tmpfs.
#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