A pod needs a read-only config file and a writable temp dir, with `readOnlyRootFilesystem: true`. How?
IntermediateScenarioConfiguration, Secrets and storage
Answer
Situation read → The security team requires an immutable container filesystem.
What I'd do →
- Set
securityContext.readOnlyRootFilesystem: true - Mount ConfigMap files with
readOnly: true - Add
emptyDirvolumes for/tmpand any cache directories the app writes - Check logs for "Read-only file system" errors and add paths accordingly
- Verify with
kubectl exec -- touch /x
Why → Immutable roots limit what an attacker can persist, and emptyDir gives the app the few writable paths it needs.
Interview tip → Good place to mention runAsNonRoot and dropping capabilities too.
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?BeginnerWhat is the difference between emptyDir, hostPath, PV/PVC and when do you use each?Beginner