How does Kubernetes storage work?

Volumes

A Volume in Kubernetes is a data storing feature with the help of which we can store data that is persistent and can be accessed by containers in a Kubernetes pod. Consider a case where an application is using a MySQL database Pod. The Data gets added, updated or deleted in the database but by default in Kubernetes when you restart the Pod all those changes will be gone because Kubernetes doesn’t give you data persistence out of the box. To solve this data persistence issue we need Kubernetes Volume that doesn’t depend on the Pod lifecycle which will still be there when Pod dies and new one gets created so that the new Pod can pick up where the previous Pod left off.

How Volumes do this is that it basically attaches a physical storage on a hard drive to your Pod. That storage could be either on a local machine (meaning on the same server node where the Pod is running) or it could be on a remote storage (meaning outside of the Kubernetes cluster).

Persistent Volumes

A PersistentVolume is a piece of storage in a Kubernetes cluster that an administrator has provisioned. PersistentVolume has a Pod independent lifecycle so it can preserve state even after a Pod dies and a new Pod is created. PersistentVolume (PV) is a Kubernetes cluster resource just like a node. A Pod is immutable therefore, when it dies, all the data created during its lifetime will be lost. Most of the applications require this characteristic of Pod but sometimes applications (for example, database applications) needs to preserve state and that is where Kubernetes PersistentVolumes (PVs) are used by the cluster administrator which can store information persistently unaffected even after Pod dies and new Pod is created.

Three important Characteristics of Kubernetes Persistent Volumes are:

  1. Persistent Volumes do not depend on the pod lifecycle.
  2. Persistent Volumes are available on all nodes.
  3. Persistent Volumes survives even if cluster crashes.

How To Share Storage Between Containers In Kubernetes ?

Kubernetes, or K8s, is an open-sourced container orchestration technology that is used to automate the manual processes of deploying, managing, and scaling applications by the help of containers. Kubernetes uses a single container per pod, which is great for most stateless applications, but some applications require more than one container to work together and require some way to persist data and share storage between pods. Sharing storage between containers in a Kubernetes cluster can be achieved with the help of Kubernetes volumes. A volume in Kubernetes is a data-storing feature with the help of which we can store persistent data that can be accessed by containers in a Kubernetes pod. In this article, we will discuss how to share storage between containers in a Kubernetes cluster using volumes.

Similar Reads

Tutorial-How to Share Storage Between Containers?

Follow this step-by-step guide to understand how to share storage between containers in a Kubernetes cluster....

How does Kubernetes storage work?

Volumes...

Static vs. Dynamic Provisioning

Static Provisioning Dynamic Provisioning Static Provisioning refers to manually creating the Storage volumes (PersistentVolumes (PVs) and PersistentVolumeClaims (PVCs) ) and managing them. With Dynamic Provisioning, the Kubernetes Storage Volumes can be created on demand. In this method, first the Cluster administrator creates the Storage and then maps that to a Persistent Volume Claim which is used by specific Pods. In Dynamic Provisioning, the cluster administrator defines the StorageClass that contains the fields provisioner, parameters and reclaim Policy. Afterwards PersistentVolumeClaims can request the StorageClass to dynamically provision the storage volumes to the pod. Static Provisioning is only useful when the Cluster administrators known about the Storage requirements already and these requirements are not expected to change frequently. It is an automated process and is used when the Storage requirements depend on dynamic workloads. It is more complex to manage and maintain at scale. This simplifies storage management and improves cluster efficiency....

Conclusion

Kubernetes or K8s is an open-sourced container orchestration technology that is used for automating the manual processes of deploying, managing and scaling applications by the help of containers. In Kubernetes, sharing storage between Containers can be achieved by the help of Kubernetes Volumes, a Volume in Kubernetes is a data storing feature with the help of which we can store data that is persistent and can be accessed by containers in a Kubernetes pod. We hope that this article taught you about how to share storage between Containers in a Kubernetes Cluster. Make sure to follow other articles on GeeksforGeeks to know about more tools in DevOps....

Sharing Storage between Containers – FAQ’s

What are Stateless applications?...