Choosing Volumes for Kubernetes Storage
Kubernetes is an open source platform for automating the deployment and orchestration of applications that run in containers. Docker is the most commonly used container platform.
In Kubernetes, the basic unit for running containers is a pod. A pod may be composed of one or more containers that form a cohesive service.
For data storage, Kubernetes could make use of the on-disk file system in a container, but with containers (and, therefore, pods) being ephemeral, any data that is stored in a container is lost if the pod is terminated or fails. Pod-based storage is not persistent by definition, which makes it necessary to use storage external to a pod.
Kubernetes provides the volume abstraction for data storage external to a pod. A volume is a directory that is accessible to all containers in the pod, and it exists as long as the pod exists. Several types of volumes are supported and are distinguished by the medium that backs the storage.
Let’s explore Kubernetes storage options based on some of the volume types.
Local device
A local volume is backed by a local storage device such as a disk, partition, or directory on a node in the Kubernetes cluster. If a pod fails or is terminated, the local volume still persists as long as the node is available, which makes a local volume durable and portable. A solid-state drive (ssd) could be used for a local volume.
Node host path
A hostPath volume mounts a file or a directory from the file system of the host node into a pod. This volume is not portable, and pods have to be scheduled by a user to specific nodes if needed for portability.
In addition to a directory or a file, a hostPath volume could be backed by a UNIX socket, character device, or block device. While these must exist at a given path, a file and directory could be created at the specified path.
NFS
An NFS volume is a network file system that is mounted into a pod. An NFS volume is persistent, and data could be added to it prior to mounting it into a pod. The volume data may be shared among multiple pods.
Cloud storage
A Kubernetes volume could be backed by cloud-based storage. Cloud storage has to be obtained through a cloud service provider, and most are supported. An open source network file system called Gluster could be used for cloud storage.
Git repo
A volume could be based on a Git repo that is mounted into a pod. Data in a Git repository persists even when a pod is terminated.
Ceph file system
A volume could be based on the Ceph file system (CFS) object storage. A Ceph storage system runs on a distributed cluster and may be accessed at object, block, and file levels.
These are just some of the more popular options for persistent storage in Kubernetes applications. Kubernetes supports many types of volumes, and a pod can use any number of them simultaneously. How that volume is used, the medium that backs its storage, and its contents are all determined by which volume type you choose.