Please provide a simple step by step guide to looking into java heap dump from a Kubernetes pod.
1 Answer
- Log in to the K8S and exec into the Pods where your java application is running.
kubectl exec -it herle-deployment-pod-5757d89d85-wrpc9 bash
get the process id (top command)
Create java heap dump
jmap -dump:live,format=b,file=<file_name>.bin <process_id>
Example:
jmap -dump:live,format=b,file=application_heap_dump.bin 1
- Copy the heap dump from pod to your local machine.
kubectl cp <pod_name>:<heap_file> <your local destination directory>
Example:
kubectl cp herle-deployment-pod-5757d89d85-wrpc9:/tmp/application_heap_dump.bin /Users/amritharajherle/Desktop/application_heap_dump.bin
- Use any memory leak analysis tool. I'm using the Eclipse's Memory Analyzer plugin.
- Open the heap dump file
- select leak suspect report
- You can check the number of objects and retained heap space. Also some possible leak suspects.
-
i am getting below error "jmap": executable file not found in $PATH": unknown command terminated with exit code 126. Feb 1, 2021 at 8:19
-
1A side note: better to run jmap without "live" to prevent GC from running before heap dump May 18, 2021 at 16:51
-
kill -3 JAVA_PID Note the process ID number of the Java process (e.g. using top, a grep on ps -axw, etc.) and send a QUIT signal to the process with the kill -QUIT or kill -3 command 1. For example: May 28, 2021 at 16:28
-
jmap does not exist in adoptopenjdk/openjdk8:alpine-slim java image, however it mostly likey jcmd would be there use this command jcmd 2960 GC.heap_dump c:/temp/heapdump.hprof Aug 6, 2021 at 15:33
-
1@VineethNG if you don't have jmap present in the image then you can use either ephemeral containers or something like robusta.dev (disclaimer: I'm the maintainer). See home.robusta.dev/java for the latter Apr 12, 2022 at 12:43