Given an webapp running with a JRE-based docker image in Kubernetes cluster, example: tomcat:9.0-jre11-temurin, then getting the thread dump is not easy as the JRE-based docker image does not include the tools like jstack, jmap...
We can use jattach tools to get our task done. TLDR; jattach is a compact tool written in C by Andrei Pangin.
First we need to download the tool to container:
Open the shell in the container:
kubectl -n default exec -it your-tomcat-pod -c your-tomcat-container -- bash
Download the jattach to the working dir
cd /working-dir curl -L -O https://github.com/apangin/jattach/releases/download/v2.2/jattach chmod +x jattach
From your terminal create thread dump and store in the output file
kubectl -n default exec your-tomcat-pod \ -c your-tomcat-container -- \ /working-dir/jattach 1 threaddump > thread-dump.txt
Then you can use jstack.review tool to analyze the thread dump.
The above is the detailed content of Get thread dump of Java container running on JRE Docker image. For more information, please follow other related articles on the PHP Chinese website!