Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Storage Kubernetes Kubernetes: From Zero to Production Module 5 - Config and Storage

Volumes and Persistent Storage in Kubernetes

Reviewed & accurate
AI Summary

What You Will Learn

Intermediate

  • Types of volumes
  • PersistentVolume and PersistentVolumeClaim
  • When to use each

Volume Types

TypeWhat it isUse case
emptyDirEmpty dir, lives with PodScratch space, sharing between containers
hostPathHost directoryNode-level access (DaemonSets)
PV/PVCPersistent, network-attachedDatabases, persistent data
configMapConfigMap as filesConfiguration files
secretSecret as filesCredentials

PersistentVolume and PersistentVolumeClaim

Terminalyaml
# PersistentVolume (PV) = actual storage
# PersistentVolumeClaim (PVC) = request for storage

# PVC requests 5GB
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: db-storage
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
Terminalyaml
# Use PVC in a Pod
spec:
  containers:
  - name: db
    image: postgres:15
    volumeMounts:
    - name: data
      mountPath: /var/lib/postgresql/data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: db-storage
PV vs PVC
PV = the actual disk (created by admin or dynamically). PVC = a request for that disk (created by developer). The app claims storage via PVC - it does not know or care where the PV is.

Practical Exercise

Create a PVC requesting 1Gi
Apply: kubectl apply -f pvc.yaml
Check: kubectl get pvc (should be Bound)
Create a Pod using the PVC
Write data, delete Pod, recreate - data persists!

Key Takeaways

  • emptyDir: temporary, deleted with Pod.
  • hostPath: host directory (node-specific).
  • PV/PVC: persistent, survives Pod deletion.
  • PVC = request for storage. PV = actual storage.
  • StorageClasses: dynamic PV provisioning (no manual PV creation).
Previously: Lesson 27 covered Secrets.
Today: You learned: Persistent data for stateful applications.
Next: Lesson 29 covers StorageClasses.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments