Special tricks to take Java memory dump from Alpine (e.g. OpenJDK-Alpine) based container which running in Azure Kubernetes Service (AKS). By adding Tini as init of container, otherwise Java process in Alpine would be using PID 1 and would make "Unable to get pid of LinuxThreads manager thread" error when taking Java memory dump (same to jcmd, jstack).
- Dockerfile <-- Sample Dockerfile with Tini, it's using openjdk:8-jdk-alpine.
- Containerized App sample in Java Springboot
Get list of POD running in AKS.
kubectl get pod
Run interactive terminal from container POD.
kubectl exec -it your-java-app-pod-name /bin/sh
Check Process ID (PID) running Java. PID not equal to 1 should be our target to take memory dump.
top
Start to take memory dump.
cd /tmp
jmap -dump:format=b,file=snapshot.jmap 1
exit
Copy out memory dump from container to your development machine.
kubectl cp your-java-app-pod-name:tmp/snapshot.jmap snapshot.jmap -n your-pod-namespace