What You Will Learn
Intermediate
- Types of volumes
- PersistentVolume and PersistentVolumeClaim
- When to use each
Volume Types
| Type | What it is | Use case |
|---|---|---|
emptyDir | Empty dir, lives with Pod | Scratch space, sharing between containers |
hostPath | Host directory | Node-level access (DaemonSets) |
PV/PVC | Persistent, network-attached | Databases, persistent data |
configMap | ConfigMap as files | Configuration files |
secret | Secret as files | Credentials |
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: 5GiTerminalyaml
# 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-storagePV 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).
Comments
Comments
Post a Comment