LAB11d: Storage Basics
LAB100: Storage Basics
apiVersion: v1
kind: Pod
metadata:
name: init-flag-demo
spec:
restartPolicy: Never
volumes:
- name: shared
emptyDir: {}
initContainers:
- name: prepare-flag
image: busybox
command:
- sh
- -c
- |
echo "Waiting remote DB service..."
sleep 30
echo "db_ready" > /work/app_run.flag
echo "Flag created."
volumeMounts:
- name: shared
mountPath: /work
containers:
- name: main-app
image: busybox
command:
- sh
- -c
- |
echo "Checking flag..."
if [ -f /work/app_run.flag ]; then
echo "Flag found. Starting app..."
sleep infinity
else
echo "Flag missing. Exiting."
exit 1
fi
volumeMounts:
- name: shared
mountPath: /workKubernetes hostPath Types — Full Table
PV, PVC, and Storageclass
PV/PVC using hostPath as backend
emptyDir-like backend using “local volume PV"
⚡ What is “local PV”?
Comparing emptyDir vs hostPath vs PV/PVC
Feature
emptyDir
hostPath
PV + PVC (hostPath/local)
🎯 How Does a PVC Know Which PV to Use?
Matching Rules (The 3-Step Algorithm)
✔️ 1. StorageClass must match
✔️ 2. AccessModes must be compatible
✔️ 3. PV capacity must be ≥ PVC capacity
If multiple PVs match?
PV
Size
If no PV matches?
Example That Makes It Click
PVC
Matching PV?
Example That Does NOT Match
Reason 1 — StorageClass mismatch
Example 2 — AccessMode mismatch
Example 3 — Size too small
Example 4 — PVC has no storageClassName
Example 5 — PV already bound
Kubernetes Storage Quick Reference Table
Default Storage Class
1. StorageClass: no-provisioner (Static PV Only)
2. StorageClass: local-storage (Local PV backend)
3. Commands: List StorageClasses
List all storage classes:
Describe a StorageClass:
4. Set a StorageClass as the Default
❓ Does a PV have to specify a StorageClass?
A PV may specify a StorageClass:
Behavior:
PV storageClassName
PVC storageClassName
Binding?
Quick Summary Table
Topic
Key Point
Last updated