What is the difference between emptyDir, hostPath, PV/PVC and when do you use each?
BeginnerScenarioConfiguration, Secrets and storage
Answer
Situation read → A developer wants scratch space and persistent storage.
What I'd do →
- emptyDir for scratch data shared across containers in a pod, lost with the pod
- hostPath mounts a node directory; avoid it except for node agents
- PVC through a StorageClass for durable data
- For memory-backed scratch use
emptyDir.medium: Memorywith asizeLimit - Choose by durability and portability needs
Why → Storage lifetime differs: pod, node, or independent of both.
Interview tip → Mention hostPath as a security risk and a PSA baseline violation.
More on Configuration, Secrets and storage
How do you inject configuration into pods and what are the options?BeginnerA ConfigMap was updated but the pod still shows old values. Why?IntermediateHow do you store a database password safely in Kubernetes?BeginnerHow do you manage secrets in GitOps without committing them in plain text?IntermediateA pod fails with `CreateContainerConfigError` and a missing key. What happened?BeginnerA StatefulSet's PVC stays Pending. How do you debug?Intermediate