-
Get the container id of the pod.
$ kubectl get po <pod-id> -o=jsonpath='{.status.containerStatuses[0].containerID}{"\n"}' | awk '{print substr($0, 10, 12);}'
NoteIn my case there is only one container, if there are mulitple container, you can use selectors.
-
Now get PIDs of Java Application in host machine.
$ docker top <container-id>
-
On host machine run below command to take thread dump.
$ kill -3 <pid>
TipBy default thread dump is redirected to standard out which in our case is docker standard out which can be access using docker logs -f <container-id>
-
Login to container
$ docker exec -it <container-id> sh
-
Get the Java PID
$ ps -eaf
-
Now execute jstack or jcmd to take thread dump
$ jcmd <PID> /tmp/Thread.print or jstack <PID> > /tmp/Thread.print
-
Exit from the contrainer and then copy the thread dump using below command.
$ docker cp <container-id>:/tmp/Thread.print .