How to get a heap dump from Kubernetes k8s pod?
- 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.