Video in progress
In Kubernetes, heap dumps, JFR recordings and GC logs filled the node's disk and caused other pods to be evicted. How do you build a diagnostic files policy at the platform level?
A separate, size-limited place for diagnostic files (an ephemeral storage limit or a separate volume), rotating logs and JFR size limits, and moving a heap dump to object storage right away and deleting it locally. I set a maximum size and a retention period for each file type.
📖 Answer
The scenario is familiar: a pod with an 8 GB heap is in a crash loop, and on every OOM an 8 GB dump is written to emptyDir. Three restarts is 24 GB, the node gets disk pressure, and the kubelet evicts other pods. One service's problem turned into a whole-node incident.
The policy I set:
Space. A separate volume for diagnostics in every pod:
volumes:
- name: diag
emptyDir: { sizeLimit: 12Gi }
containers:
- resources:
limits: { ephemeral-storage: 14Gi }
If sizeLimit is exceeded, only that pod is evicted, not its neighbors. For services with big heaps, remember that the dump volume has to be larger than the heap.
Limits by file type:
- GC log:
filecount=5,filesize=20m, at most 100 MB; - JFR:
maxsize=500m,maxage=6h; - hs_err and core dumps: core dumps are usually off, and enabled separately when needed;
- heap dump: a single file. If
HeapDumpPathis a directory, the JVM writesjava_pid<pid>.hprof: with a new PID each time the files pile up in a crash loop (in a container the PID is often 1, so the name repeats and, if the file already exists, the dump is not written). The file must be deleted after it is uploaded.
Moving. A sidecar or a preStop/entrypoint script compresses the dump when it appears, uploads it to an encrypted bucket and deletes it locally. The bucket has a TTL (say, 14 days) and access control, because dumps contain personal data.
Crash loop protection. On repeated OOMs only the first dump is needed. A script implements the logic "if there is a dump from the last hour, don't write a new one", or the dump volume is sized to fit just one file.
Monitoring. An alert on ephemeral storage use per node and on eviction events.
All of this shouldn't be left to the service teams' discretion: it should come as a default in the base image and the Helm chart template. Diagnostic data is the most valuable thing during an incident, and losing it or losing a node because of it are equally bad.
Sign up to mark studied questions and save your progress.