Volumes in Kubernetes
Shreyansh Sinha
SWE at Microsoft | Ex Siemens Healthineers, JP Morgan Chase | Hackerrank Certified at Problem Solving | Open for Mentor/Instructor Roles | DM for Collaborations.
Containers
Container (can be thought of as a light weight virtual machine) runs logically in a pod.
Pod is a group of one or more containers.
Nodes have worker machines (worker nodes) that host the pods.
Cluster is a group of nodes that run our containerized applications.
In between the three terms Container, Pod and Cluster, we have following relationship :
?????????????Container => Pod => Nodes => Cluster.
Volumes
Every container which runs in a pod can read and write to its own isolated file system. But every time the container is restarted, the filesystem gets destroyed, hence there is lack of persistent data storage. This is where concept of volumes comes into picture.
To brief, volumes in Kubernetes represent a directory with data that is accessible across multiple containers in a Pod.
But again, there is a problem here. The data in the volume gets destroyed when the pod is restarted. The final solution to all these issues is Persistent Volumes. With the help of persistent volumes, the data storage outlives the containers in a Pod and provides long term storage to our Kubernetes cluster.
How to Create Volumes ?
There are two steps, one step involves specifying the volume for the pod and second involves mounting that volume (volumeMounts) at a specific path (mountpath) inside the container file system.
领英推荐
Let us try to understand this yaml file from understanding volume perspective. This is a simple pod whose name is nginx-secret-store. Next field is spec.
Spec field is where we describe the object in greater detail. This is where we describe our containers and volumes.
Note that each volume has a name and configuration based on the type of volume. In our case name of volume is secrets-store-online and it is a csi volume type. Next, we look at containers field. It has a name, and volumeMounts.
volumeMounts has the location where the volume will be mounted inside the file system. Note that the name sub-field should have same value inside the “volumes” and “volumeMounts” field.
We can ignore other details for now.
Types of Volumes
Mainly, volumes are categorized into two types
1)?????Those volumes who have lifetime of pod but get destroyed on container restart.
Example: emptyDir, configMap, secret etc.
2)?????Those volumes which persist across containers and restarting of pods.
Example: persistentVolumeClaim, azureDisk etc.
References : Wikipedia, Kubernetes docs etc.