Kubernetes Storage: From Persistent Volumes to NFS to Native Storage

Containers have quickly become the standard for application deployment. Containers are units of software that package up code and all dependencies so that an application is able to run quickly and reliably in various computing environments, from OnPremise to OnCloud deployments.

With containers comes the need for managing them, and to this end, Kubernetes has emerged as the leading container orchestration software. Kubernetes is a portable, extensible, open-source platform for managing containerized workloads. It facilitates declarative configuration and automation, takes care of scaling and failing over applications, provides deployment patterns, and more. Containers and Kubernetes were originally designed to support stateless workloads, but a lot of effort has been made to support stateful applications. Stateful applications need to use persistent storage systems to provide data persistence. These requirements apply to the ProTego Toolkit. In this Blog we will explore how we have addressed some of these Kubernetes storage concepts and challenges.

Container Storage is Ephemeral

Files in a container are ephemeral, which presents some problems for stateful applications when running in containers. One problem is the loss of files when the container crashes. Kubernetes restarts the container but with a clean state. Another problem occurs when sharing files between containers. Kubernetes Persistent Volumes solve such problems.

Persistent Volumes and Persistent Volume Claims

A Persistent Volume Kubernetes resource is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes.

A Persistent Volume Claim is a request for storage, for a specific Persistent Volume or Storage Class, which will be mapped within a Pod to a container directory.

Typically, Persistent Volumes use local filesystem for data persistence, but some other issues arise in multi-node clusters. If a Pod with a local Persistent Volume crashes, Kubernetes may choose to deploy it to a different node. In that case, data is not moved to the new node, resulting in data loss from the application. Another issue arises when different pods need to share a Persistent Volume, in which case both Pods need to be in the same node to access the same data in the Persistent Volume.

In order to solve these challenges, Network File System (NFS) could be used as shared storage for the cluster.

NFS Persistent Volumes

NFS is a distributed file system protocol to allow a user on a client machine to access files over the network from a server machine, much like local storage is accessed.

Kubernetes allows the creation of NFS Persistent Volumes, in much the same way as local filesystem Persistent Volumes, just indicating the type “nfs”, the name/ip of the NFS server and the path of the exported volume. An NFS Persistent Volume allows an existing NFS share to be mounted into a Pod. Contents of the NFS are preserved, thus allowing volumes to be pre-populated with data and data to be shared between Pods by using a Persistent Volume Claim to the same NFS Persistent Volume.

There are however some drawbacks to using NFS, including performance (mainly due to the network latency), limited High Availability (HA) and replication of data, compatibility with Kubernetes native backup solutions, etc.

These challenges are addressed by using Kubernetes Native Storage solutions.

Kubernetes Native Storage

Kubernetes has defined specifications for storage through the Container Storage Interface (CSI) which provides a standard and portable approach to implement and consume storage services for containerized workloads.

The idea is to use software-defined storage controllers, deployed in the Kubernetes cluster, which provide an abstraction layer of distributed persistent storage to the Pods or containers. Different storage technologies implementing the CSI specification may provide different features like HA, data replication, etc.

Storage is provided to the Pods using the same Kubernetes resources as in the previous storage systems, i.e. Persistent Volumes and Claims or StorageClasses for dynamic provisioning.

There are various open-source projects providing software-defined native storage controllers, with Ceph, Longhorn, Rook and OpenEBS among the most popular ones, and also some commercial offerings such as Kubera, Trident, Portworx and StorageOS. In addition, cloud vendors also provide CSI plugins in order to use their storage technologies e.g. Amazon AWS for EFS or EBS, Google, Azure, etc.

Summary

Storage is a critical issue for modern containerized applications deployed on Kubernetes. Kubernetes has evolved from using local node filesystems mounted in the containers to using NFS, and finally to using native storage, defined by the CSI specification, which allow persistence and sharing of data.

These different storage options have been explored in the ProTego project, in order to provide storage systems appropriate to the various components use cases and deployments.

This blog post was written for the ProTego project by Noel Tomas (ICE).