Getting Started with Volumes

Learn about Kubernetes volumes and how to create a cluster with them.

State preservation

Note: Having a system without a state is impossible. Even though there is a tendency to develop stateless applications, we still need to deal with the state. There are databases and other stateful third-party applications. No matter what we do, we need to make sure that the state is preserved regardless of what happens to containers, Pods, or even whole nodes.

Most of the time, stateful applications store their state on disk. This leaves us with a problem. If a container crashes, kubelet will restart it. The problem is that it will create a new container based on the same image. All data accumulated inside a container that crashed will be lost.


Kubernetes volumes solve the need to preserve the state across container crashes. In essence, volumes are references to files and directories that are accessible to containers that form a Pod. The significant difference between different types of Kubernetes volumes is in the way these files and directories are created.

While the primary use case for volumes is the preservation of the state, there are quite a few others. For example, we might use volumes to access Docker’s socket running on a host. Or we might use them to access configuration residing in a file on the host file system.

Note: We can describe volumes as a way to access a file system that might be running on the same host or somewhere else. No matter where that file system is, it is external to the containers that mount volumes. There can be many reasons why someone might mount a volume, with state preservation being only one of them.

There are over 25 volume types supported by Kubernetes. It would take us too much time to go through all of them. Besides, even if we’d like to do that, many volume types are specific to a hosting vendor. For example, awsElasticBlockStore works only with AWS, azureDisk and azureFile work only with Azure, and so on.

We’ll limit our exploration to volume types that can be used within k3d. You should be able to extrapolate that knowledge to volume types applicable to your hosting vendor of choice.

Get hands-on with 1200+ tech skills courses.