How to get a heap dump from Kubernetes k8s pod?
17,893
- 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.
Author by
Amrith Raj Herle
IoT Enthusiast,Interested in Big Data,Data Analytics, AI & Machine learning. Docker ¦ Kubernetes ¦ Micro Service ¦ Jenkins ¦ IBM Cloud ¦ PostgreSQL ¦ DB2 ¦ Cloudant ¦ Java(Hibernate, JPA, GWT, Sencha GXT) ¦ Tibco BW ¦ SonarQube ¦ Apache Camel ¦ openAPI ¦ osgi ¦ TensorFlow ¦ Arduino ¦ IBM RAD certified application developer ¦ Agile Development ¦ IBM BPM Java API ¦ AppWay Client onboarding tool (BPMN) ¦ PyQT skills.
Updated on July 25, 2022Comments
-
Amrith Raj Herle almost 2 years
Please provide a simple step by step guide to looking into java heap dump from a Kubernetes pod.
-
Vineeth NG about 3 yearsi am getting below error "jmap": executable file not found in $PATH": unknown command terminated with exit code 126.
-
vinayhudli almost 3 yearsA side note: better to run jmap without "live" to prevent GC from running before heap dump
-
Ankireddy Polu almost 3 yearskill -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:
-
Gustavo Alexandre over 2 yearsjmap 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
-
Admin over 2 yearsPlease remove
/tmp
from example you provided in p.4. or add/tmp
in p.3 -
chandu ram over 2 yearsGetting jmap not found error. Using the jdk. openjdk version "11.0.13" 2021-10-19 LTS OpenJDK Runtime Environment 21.10-(Zulu-11.52+13-linux-musl-x64)-Microsoft-Azure-restricted (build 11.0.13+8-LTS) OpenJDK 64-Bit Server VM 21.10-(Zulu-11.52+13-linux-musl-x64)-Microsoft-Azure-restricted (build 11.0.13+8-LTS, mixed mode)
-
Natan Yellin about 2 years@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