Day 09 Storage in Kubernetes

Day 09 Storage in Kubernetes

Managing storage is a distinct problem from managing to compute instances.

Containers/Pods are ephemeral so On-disk files too. it creates many problems for non-trivial applications running in containers. One of the biggest problems is the loss of files when a container crashes. The Kubelet service will restart the container but with a clean state.

To overcome this, we have volumes in Kubernetes that helps us persist data, no matter what happens with pods/containers we always have data available when needed.

Storage Classes

A StorageClass provides a way for administrators to describe the "classes" of storage they offer. Different classes might map to quality-of-service levels, or to backup policies, or to arbitrary policies determined by the cluster administrators. Kubernetes itself is unopinionated about what classes represent. This concept is sometimes called "profiles" in other storage systems.

Each StorageClass contains the fields provisioner, parameters, and reclaimPolicy, which are used when a PersistentVolume belonging to the class needs to be dynamically provisioned.

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard
provisioner: kubernetes.io/aws-ebs
parameters:
  type: gp2
reclaimPolicy: Retain
allowVolumeExpansion: true
mountOptions:
  - debug
volumeBindingMode: Immediate

PersistentVolume (PV)

A PersistentVolume (PV) is a resource in the cluster just like a node is a cluster resource.

PVs are volume plugins like Volumes, but have a lifecycle independent of any individual Pod that uses the PV.

PersistentVolumeClaim (PVC)

A PersistentVolumeClaim (PVC) is a request for storage by a user/pod/container. It is similar to a Pod.

Pods consume node resources and PVCs consume PV resources. Pods can request specific levels of resources (CPU and Memory). Claims can request specific size and access modes (e.g., they can be mounted ReadWriteOnce, ReadOnlyMany or ReadWriteMany, see AccessModes).

Persistent Volume Life Cycle

  1. Provisioning

    • Static

    • Dynamic

  2. Binding

  3. Using

  4. Reclaiming

Storage is indeed one of the crucial part of kubernetes lifecycle. In upcoming blog will cover how effectively we can use PVC and PV, with some real usecases.

Made with ❤️ by Pratikkumar Panchal