20

Please provide a simple step by step guide to looking into java heap dump from a Kubernetes pod.

1 Answer 1

27
  1. 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
  1. get the process id (top command)

  2. 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
  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
  1. Use any memory leak analysis tool. I'm using the Eclipse's Memory Analyzer plugin.
  • Open the heap dump file

Open the heap dump file

  • select leak suspect report

select leak suspects report

  • You can check the number of objects and retained heap space. Also some possible leak suspects.
7
  • i am getting below error "jmap": executable file not found in $PATH": unknown command terminated with exit code 126.
    – Vineeth NG
    Feb 1, 2021 at 8:19
  • 1
    A side note: better to run jmap without "live" to prevent GC from running before heap dump
    – vinayhudli
    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

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.