How to get a heap or thread dump from JVM inside a pod in Kubernetes?
Using JDK tools inside the Kubernetes
1- Connect to the POD
2- Get the heap and thread dump
3- Copy dump files to your machine
When you run Java programs on a desktop or a server, you can quickly get heap or thread dump using JDK tools like jmap
, jstack
Or other tools and commands.
But in the Kubernetes environment, you don't have access to the container in which your java application is included directly. So you need to do some extra steps to get the heap or thread dump from the JVM inside the pod.
1- Connect to the POD
First, you need to connect to the pod which is running your Java application. For this purpose, you can get the shell to that pod using this command:
kubectl exec -it POD_NAME -- /bin/bash
and then you can get the heap or thread dump by using the jmap
or jstack
.
Or
You can directly run the jmap
or jstack
command using the kubectl
command:
kubectl exec POD_NAME -c CONTAINER_NAME -- bash -c "COMMAND TO GET HEAP OR THREAD DUMP"