Video in progress
A pod was evicted with "The node was low on resource: ephemeral-storage". What is this, and how do you prevent it in a Java service?
Ephemeral storage is the container's writable layer, emptyDir volumes and the container logs on the node. If the app writes a big file to /tmp, a heap dump, or a log file, the node disk fills up and the kubelet evicts pods. You need to set limits and control such writes.
📖 Answer
The kubelet watches the node's disk and evicts pods when it runs short. The ones using more ephemeral storage than their requests go first.
Typical culprits in a Java service:
- Tomcat writes multipart uploads to a temp folder: a 2 GB file is uploaded, then another, then another;
-XX:HeapDumpPath=/tmp: a 4 GiB heap dump;- Logback writes both to a file and to stdout: the file is in the container layer, and stdout is on the node under
/var/log/pods, so the space is used twice; - temporary export files (CSV, PDF) are never deleted.
resources:
requests:
ephemeral-storage: "1Gi"
limits:
ephemeral-storage: "4Gi" # if exceeded, only this pod is evicted
volumes:
- name: tmp
emptyDir:
sizeLimit: 2Gi
With a limit set, the problem does not spread to the neighbors: instead of waiting for the node to fill up, exactly the "greedy" pod is evicted. kubectl describe pod shows Evicted and the reason.
On the application side: stream uploads straight to S3/MinIO, limit spring.servlet.multipart.max-file-size, delete temp files in finally, write the heap dump to a separate volume. Logs go to stdout only.
Sign up to mark studied questions and save your progress.