I found the below two ways to investigate the out of memory error
in the Kubernetes. Either it would be best if you had a logging solution that will keep the logs or you can use --previous
run to read the logs, which I generally use for debugging until it is the same
pod that is in crashloop
.
Write thread to stdout of the pod
You can take advantage of the lifecycle
hook, and take a thread dump
and write to stdout, so you will be able to see at k logs -f pod_name -c container_name --previous
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "jcmd 1 Thread.print > /proc/1/fd/1"]
pod-lifecycle
This will also help if you write dumb logs to Datadog or Elasticsearch.
Writing to volume
you will need to update the java
command or env
and deployment chart.
serviceAccountName: {{ include "helm-chart.fullname" . }}
volumes:
- name: heap-dumps
emptyDir: {}
containers:
- name: java-container
volumeMounts:
- name: heap-dumps
mountPath: /dumps
add this env
ENV JAVA_OPTS="-XX:+CrashOnOutOfMemoryError -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps/oom.bin -Djava.io.tmpdir=/tmp"
you will be able to see what's going on in the JVM.
Some more config regarding JVM in the container that can help you to utlizie the advance option of the JVM running inside container.
-XX:InitialRAMPercentage=50.0 -XX:MinRAMPercentage=50.0 -XX:MaxRAMPercentage=85.0
he JVM has been modified to be aware that it is running in a Docker container and will extract container specific configuration information instead of querying the operating system.
jvm-in-a-container
best-practices-java-memory-arguments-for-containers