Kubernetes Volumes — INTRODUCTION

ujjwal bansal
3 min readApr 21, 2022

Before taking our discussion toward Kubernetes, I feel we should properly educate ourselves with the difference between Storage and Volume?

Storage: Without going into much technical details you just need to know our hard drive, flash drive, floppy discs, compact disks, DVDs are all examples of storage.

Figure - 1

Suppose we have a total storage of 1 TB and we make a partition of 100 GB. This partition is of no use and we cannot store any data until it has been formatted into a file system like NTFS, FAT32, ext4, etc. When this partition get formatted, it becomes a volume and become usable.

So, we can say a volume is just a storage with a filesystem. Now, we can start discussion about Kubernetes volume.

Docker images are read-only…

Figure — 2

Let’s talk something basic about filesystem of containers living inside pods. Containers are just an outer casing of images of our applications. And these docker images are read-only, so when we need to update any file from the images, we are actually updating a copy of the file in writable layer which is present in the filesystem of the container. Every container has a writable storage layer as shown in figure — 2.

Figure — 2 showing a pod with two containers inside and each container in a pod has its own file system, which is constructed by Kubernetes.

Why we need storage volumes in Kubernetes?

We know that containers in a pod get restarted ( either because the process died or Kubernetes find out that container wasn’t healthy any more) and new container will not see anything that was written to the filesystem by the previous container, even though newly started container runs in the same pod.

Here comes the answer to our question, why we need storage volumes in Kubernetes? Suppose in some scenarios we want the new container to continue where the last one finished. We may not need the whole filesystem that was used by old container but we may want to preserve the directories that hold actual data.

Storage Volumes

In the picture of container and pods we need a storage which is part of a pod and share the same lifecycle as the pod. And volume is exactly the thing we are looking for. Volume is created when the pod is started and is destroyed when the pod is deleted. Because of this, a volume’s contents will persist across container restarts. After the container is restarted, the new container can see all the files that were written to the volume by the previous container.

Figure — 3

As shown in Figure — 3 we can also connect multiple containers into a single volume. And each volume is connected with certain mount point of the container.

NOTE: If you have problem in understanding what is mount point. Please refer to my article.

We can end this article here and I will explain more about Kubernetes volume in my upcoming articles.

Credits

  • Kubernetes in Action by Marko Luksa.
  • Learn Kubernetes in a month of lunches by Elton Stoneman.

Resources

  1. For more detail on other disk terminology

--

--

ujjwal bansal

Propagating a life-changing perspective to everyone is my motive. Writing my own expirences or learnings to empower others.