Storage Classes
Kubernetes storage classes define how persistent volumes are provisioned in the K3s cluster.
Available Storage Classes
| Storage Class | Provisioner | Reclaim Policy | Default | Notes |
|---|---|---|---|---|
| local-path | rancher.io/local-path | Delete | Yes (K3s default) | Uses local node storage |
| longhorn | driver.longhorn.io | Delete | No | Distributed replicated storage |
local-path (K3s Default)
The K3s default storage class uses the local-path provisioner, which creates PersistentVolumes on the local filesystem of the node where the pod is scheduled.
- Pros: Simple, fast, no additional infrastructure
- Cons: No replication, data lost if node fails, pod-to-node affinity required
- Best for: Non-critical workloads, ephemeral data, development environments
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
storageClassName: local-path
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
Longhorn (Distributed)
Longhorn provides distributed block storage with replication across the three cluster nodes (megatron, thing1, thing2).
- Pros: Data replication (configurable replicas), snapshots, backups, web UI
- Cons: Higher resource overhead, network-dependent I/O, more complex
- Best for: Databases, stateful applications, anything requiring data durability
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-durable-pvc
spec:
storageClassName: longhorn
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
Quick Commands
# List storage classes
kubectl get storageclass
# List persistent volumes
kubectl get pv
# List persistent volume claims across all namespaces
kubectl get pvc -A
# Check Longhorn volumes
kubectl get volumes.longhorn.io -n longhorn-system
# Check Longhorn replicas
kubectl get replicas.longhorn.io -n longhorn-system
Choosing a Storage Class
| Use Case | Recommended Class | Reason |
|---|---|---|
| Database (production) | longhorn | Replication for durability |
| Database (dev) | local-path | Performance, simplicity |
| Container registry | longhorn | Large volumes, durability |
| Temporary build artifacts | local-path | Speed, disposable |
| Secrets/config | longhorn | Durability across restarts |
TODO: expand with Longhorn backup configuration, snapshot policies, and volume health monitoring.