MahmooDs
MahmooDs

Reputation: 153

How to get Java Heap Dump from a Kubernetes Pod using jmap?

I was following the steps mentioned here How to get a heap dump from Kubernetes k8s pod?

I'm able to get the the process id using top command inside the pod. However, when I run jmap I get this:

~ $ jmap
sh: jmap: not found

I access the pod with this command: kubectl exec -it -- sh

I also tried this command:

kubectl exec -it <pod> -- jmap -dump:live,format=b,file=heapdump.bin 1

But I was getting:

OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"jmap\": executable file not found in $PATH": unknown command terminated with exit code 126

Is there any other way to get the java heap dump from the pod?

Upvotes: 0

Views: 10983

Answers (1)

Normally containers are limited on the tools available(like you get 'more', but you don't get 'less'), so the tools available for you depends on your container.

The 2 tools that are used to get a heap dump are jmap and jcmd, check if you got jcmd in the container.

https://www.adam-bien.com/roller/abien/entry/taking_a_heap_dump_with

If not, I recommend to put the java app in a container that has either jmap or jcmd and then run it; even if the container is "heavier" that won't affect the java app nor the heap dump so it will be the same.

If that's not an option, maybe this will be https://techblog.topdesk.com/coding/extracting-a-heap-dump-from-a-running-openj9-java-process-in-kubernetes/ (not mine).

Upvotes: 4

Related Questions