top of page
Writer's picturevP

Persistent Storage in Kubernetes - Day 54

Welcome back to our #90DaysOfDevOps journey! Today, we'll be discussing about Persistent Storage in Kubernetes, a crucial aspect when dealing with stateful applications and preserving data across container lifecycles.


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


Persistent Volumes (PVs)

In Kubernetes, a Persistent Volume (PV) represents a piece of storage in the cluster. It's a resource in the cluster that exists independently of any Pod and can be dynamically or statically provisioned. PVs have a lifecycle independent of any individual Pod that uses the PV.

Here's a basic example of a PV manifest:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/mnt/data"

This PV is using a hostPath as its storage medium, residing at /mnt/data on the host.


Persistent Volume Claims (PVCs)

A Persistent Volume Claim (PVC) is a request for storage by a user. It allows a user to consume abstract storage resources without having to concern themselves with the details of storage provision.

A PVC manifest might look like this:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: my-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

This PVC requests 3 gigabytes of storage with a ReadWriteOnce access mode.


Managing Stateful Applications in Kubernetes

StatefulSets: Bringing Order to Statefulness

When dealing with stateful applications, Kubernetes provides a controller called StatefulSet. It is similar to a Deployment but designed for stateful applications.

A StatefulSet maintains a sticky identity for each of its Pods, allowing for stable network identities and persistent storage.


In Practice: PVs, PVCs, and StatefulSets

  1. Create a Persistent Volume (PV): Use kubectl apply -f pv.yaml with the above PV manifest to create a PV.

  2. Claim Storage with PVC: Deploy a PVC using kubectl apply -f pvc.yaml to request storage.

  3. Deploy a StatefulSet: Utilize a StatefulSet manifest to deploy stateful applications that require persistent storage.

  4. Observing Stateful Behavior: Note how Pods in a StatefulSet maintain stable network identities and preserve storage across restarts.

Mastering Persistent Volumes, Persistent Volume Claims, and StatefulSets is crucial for handling stateful applications in Kubernetes. These tools provide the stability and data persistence required for applications that rely on maintaining state.


With this, I'll conclude this post.


Thank you for reading!


*** Explore | Share | Grow ***

6 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page