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:
- Persistent Volumes do not depend on the pod lifecycle.
- Persistent Volumes are available on all nodes.
- 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.