Thuta Learning
IntermediateDevOpsintermediate

Volumes & Storage

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Volumes & Storage without feeling intimidated by them
  • Get comfortable running the kubectl commands/YAML yourself
  • Be able to apply this concept immediately in a real project

Let's think about it this way for a second

A container's filesystem is ephemeral (temporary) — every time a pod restarts or gets recreated, everything inside it is gone. For an app that needs to hold onto data, like a database, that's a serious problem. A Volume connects storage outside the container's filesystem — a PersistentVolume (PV) is a storage resource (disk space) that the cluster admin has provisioned, while a PersistentVolumeClaim (PVC) is the request an app makes saying 'I need this much storage.'

Let's connect this to a real scenario

If a database Pod (say, PostgreSQL) has a PVC attached, then even if the pod crashes and gets recreated, the data in the PVC (customer records, order history) will still be there — the new pod just reattaches to the same old PVC. On local minikube, you can use the `hostPath` volume type for testing (in production you'd use cloud disks, like AWS EBS).

Let's look at it together

yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: db-storage
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: db-pod
spec:
  containers:
    - name: postgres
      image: postgres:16
      volumeMounts:
        - mountPath: /var/lib/postgresql/data
          name: db-vol
  volumes:
    - name: db-vol
      persistentVolumeClaim:
        claimName: db-storage
You should see
$ kubectl get pvc db-storage
NAME         STATUS   VOLUME     CAPACITY   ACCESS MODES
db-storage   Bound    pvc-xxxx   1Gi        RWO

5-Minute Try-It

Create a PVC, mount it into a Pod, write a file, then delete the pod with `kubectl delete pod` and check whether the data is still there once the new pod comes back up.

A Quick Word of Caution

Deleting a PVC (depending on the reclaim policy) can mean the data inside is gone for good — always check you have a backup before deleting a production database volume.

Easy traps

  • Running a database Pod directly without attaching a PVC — every pod restart can wipe out all the data
  • Requesting way more storage size than a PVC actually needs (which racks up cost on cloud storage)

Now Try It Yourself

Create a PVC, mount it into a Pod, write a file, then delete the pod with `kubectl delete pod` and check whether the data is still there once the new pod comes back up.

You'll know it worked when: $ kubectl get pvc db-storage NAME STATUS VOLUME CAPACITY ACCESS MODES db-storage Bound pvc-xxxx 1Gi RWO

Volumes & Storage | Thuta Learning