/tmp.
Table of Contents
- Problem Overview
- Initial Deployment Configuration
- Why
readOnlyRootFilesystemIsn’t Applied - Original Deployment Script Analysis
- Quick Workaround: Always Apply Manifest
- Solution: Mounting an
emptyDirVolume - Applying the Updated Manifest
- Verification Steps
- Best Practices
- References
Problem Overview
You’ve addedreadOnlyRootFilesystem: true to your container’s securityContext, but after deployment, the pod spec doesn’t reflect this change. The Deployment script only updates the image, never reapplies the full YAML, so new securityContext settings are ignored.
Initial Deployment Configuration
Why readOnlyRootFilesystem Isn’t Applied
Because the deployment script checks for an existing Deployment and only runs kubectl set image…, it never reapplies the manifest changes (securityContext, volumes, etc.).
Original Deployment Script Analysis
Quick Workaround: Always Apply Manifest
Always applying the full manifest will restart pods and may cause brief downtime. Plan for rolling updates.
/tmp is on a read-only root, the Spring Boot app can’t create its temp directory.
Solution: Mounting an emptyDir Volume
To provide a writable /tmp while keeping the rest of the filesystem read-only, add an emptyDir volume and mount it at /tmp.
The
emptyDir volume is ephemeral and only persists for the pod’s lifetime. Use a PersistentVolume if you need data durability.Applying the Updated Manifest
Verification Steps
| Step | Command | Expected Output |
|---|---|---|
| 1. Check pods are running | kubectl get pods | All pods in Running state |
| 2. Confirm readOnlyRootFilesystem | kubectl get po devsecops-xxx -o yaml | grep readOnlyRootFilesystem | readOnlyRootFilesystem: true |
3. Test write to /etc | kubectl exec -it devsecops-xxx -- touch /etc/deny && echo ok | touch: cannot touch '/etc/deny': Read-only file system |
4. Test write to /tmp | kubectl exec -it devsecops-xxx -- touch /tmp/allow && echo ok | ok |
| 5. Verify application startup logs | kubectl logs devsecops-xxx | Tomcat and Spring Boot start messages |
Best Practices
| Resource | Purpose | Reference |
|---|---|---|
| securityContext | Enforce container security policies | Kubernetes Docs |
| emptyDir volume | Provide ephemeral writable storage | emptyDir Volume |
| Rolling Updates | Minimize downtime when applying new manifests | Deployments |