Skip to content

Working with Storage

Estimated time to read: 3 minutes

Kubernetes (k8s) offers a flexible and scalable storage management system for containers running within a cluster. The storage in Kubernetes can be broadly categorized into two types: ephemeral (temporary) storage and persistent storage.

1. Ephemeral Storage:

Ephemeral storage is tied to the lifecycle of a Pod. When a Pod is deleted, the storage is also deleted. This type of storage is suitable for use cases where data doesn't need to persist after the Pod is terminated. emptyDir

  • emptyDir: As mentioned earlier, emptyDir is a temporary directory that is created when a Pod is assigned to a Node and deleted when the Pod is removed.
  • ConfigMap and Secret: These are used to store configuration files and sensitive data like passwords, respectively. They can be mounted as volumes, but the data is not meant to persist beyond the Pod's lifecycle.
  • Downward API: Provides metadata about the Pod or the node where the Pod is running, available as a volume.

2. Persistent Storage:

Persistent storage, on the other hand, is designed to outlive the Pod that uses it. It allows data to be retained across Pod restarts, enabling stateful applications to function effectively in Kubernetes.

Persistent Volumes (PVs) and Persistent Volume Claims (PVCs):

  • Persistent Volume (PV): A Persistent Volume is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using StorageClasses. It is independent of the Pod's lifecycle, meaning the data stored in a PV can survive after the Pod is deleted.

  • Persistent Volume Claim (PVC): A PVC is a request for storage by a user. It is similar to a Pod requesting CPU or memory resources. PVCs are bound to PVs, and they can request specific storage size, access modes (e.g., ReadWriteOnce, ReadOnlyMany, ReadWriteMany), and storage class.

Common Storage Solutions in Kubernetes:

  1. NFS (Network File System): NFS is a distributed file system that allows multiple nodes to share storage. It is suitable for ReadWriteMany access mode, where multiple Pods across different nodes can read and write data simultaneously.

  2. Cloud Storage:

    • AWS EBS (Elastic Block Store): A block storage service provided by AWS that can be used as a PV in Kubernetes. It supports ReadWriteOnce, meaning it can be attached to a single Pod at a time.
    • GCP Persistent Disks: Similar to AWS EBS but provided by Google Cloud Platform. It supports ReadWriteOnce.
    • Azure Disks and Azure Files: Azure Disks provide block storage, while Azure Files offer file storage that can be shared across multiple Pods.
    • CSI (Container Storage Interface): CSI is an industry-standard that Kubernetes uses to interface with various storage solutions. CSI drivers can be used to manage storage for a wide range of environments, from cloud-based storage to on-premises solutions.
  3. Ceph: A distributed storage system that provides object, block, and file storage. Ceph can be integrated with Kubernetes using the Rook operator, which allows Kubernetes to manage Ceph clusters and use Ceph-based storage.

  4. GlusterFS: Another distributed file system that allows for scalable storage in Kubernetes.