What Is Persistent Storage in Kubernetes? | FinOps Glossary

Kubernetes Persistent Storage

In Kubernetes, persistent storage refers to storage that retains data even after the lifecycle of a pod ends. This is essential for stateful applications, where data must persist beyond individual pod restarts, rescheduling, or failures. Kubernetes provides a system to manage persistent storage using Persistent Volumes (PVs) and Persistent Volume Claims (PVCs), allowing users to easily attach long-term storage to their applications running within the cluster.

How Persistent Storage Works in Kubernetes

Persistent storage in Kubernetes decouples the storage lifecycle from the pod lifecycle, ensuring that data persists even if the pod accessing it is terminated or rescheduled. Here’s how it works:

  1. Persistent Volumes (PV):
  1. Persistent Volume Claims (PVC):
  1. Storage Classes:

Example of Persistent Storage Use Case

Imagine you are running a MySQL database in your Kubernetes cluster. Databases require persistent storage to retain data like user records, settings, and transactions even if the database container is restarted or moved to another node. By using a Persistent Volume, the MySQL data will persist, allowing the database to recover from disruptions without losing information.

How to Configure a Pod to Use Persistent Storage

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 10Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /mnt/data
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
  - name: my-container
    image: mysql:5.7
    volumeMounts:
    - mountPath: "/var/lib/mysql"
      name: my-storage
  volumes:
  - name: my-storage
    persistentVolumeClaim:
      claimName: my-pvc

Explanation of Configuration:

  1. Persistent Volume (PV): This configuration reserves 10Gi of storage on the host path /mnt/data and can be accessed by pods that use a matching PVC. The reclaim policy is set to Retain, meaning that the data on the PV will be preserved even after the PVC is deleted.
  2. Persistent Volume Claim (PVC): This acts as a request for the 10Gi of storage. Kubernetes will bind this PVC to the PV if it matches the storage request and access mode.
  3. Pod Configuration: The pod specifies a volumeMount to mount the storage from the PVC to /var/lib/mysql, which is the directory MySQL uses to store its data. When the pod writes to this directory, the data will be saved on the persistent storage specified by the PV.

References

  1. Kubernetes Documentation: Storage Classes
  2. Red Hat: Persistent Storage in Kubernetes
  3. AWS Documentation: Amazon EBS – Persistent Block Storage