<p>We are running our kafka stream application on Azure kubernetes written in java. We are new to kubernetes. To debug an issue we want to take thread dump of the running pod.</p>
<p>Below are the steps we are following to take the dump.</p>
<ol>
<li><p>Building our application with below docker file.</p>
<pre><code>FROM mcr.microsoft.com/java/jdk:11-zulu-alpine
RUN apk update &amp;&amp; apk add --no-cache gcompat
RUN addgroup -S user1 &amp;&amp; adduser -S user1 -G user1
USER user1
WORKDIR .
COPY target/my-application-1.0.0.0.jar .
</code></pre>
</li>
<li><p>Submitting the image with below deployment yaml file</p>
</li>
</ol>
<p>apiVersion: apps/v1
kind: Deployment
metadata:
name: my-application-v1.0.0.0
spec:
replicas: 1
selector:
matchLabels:
name: my-application-pod
app: my-application-app
template:
metadata:
name: my-application-pod
labels:
name: my-application-pod
app: my-application-app
spec:
nodeSelector:
agentpool: agentpool1
containers:
- name: my-application-0
image: myregistry.azurecr.io/my-application:v1.0.0.0
imagePullPolicy: Always
command: [&quot;java&quot;,&quot;-jar&quot;,&quot;my-application-1.0.0.0.jar&quot;,&quot;input1&quot;,&quot;$(connection_string)&quot;]
env:
- name: connection_string
valueFrom:
configMapKeyRef:
name: my-application-configmap
key: connectionString
resources:
limits:
cpu: &quot;4&quot;
requests:
cpu: &quot;0.5&quot;</p>
<ol start="3">
<li><p>To get a shell to a Running container you can run the command below:</p>
<p>kubectl exec -it &lt;POD_NAME&gt; -- sh</p>
</li>
<li><p>To get thread dump running below command</p>
<p>jstack PID &gt; threadDump.tdump</p>
</li>
</ol>
<p>but getting permission denied error
<a href="https://i.stack.imgur.com/TKfeE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TKfeE.png" alt="enter image description here" /></a></p>
<p>Can some one suggest how to solve this or steps to take thread/heap dumps.
Thanks in advance</p>

<p>Since you likely need the thread dump locally, you can bypass creating the file in the pod and just stream it directly to a file on your local computer:</p>
<pre><code>kubectl exec -i POD_NAME -- jstack 1 &gt; threadDump.tdump
</code></pre>
<p>If your thread dumps are large you may want to consider piping to <code>pv</code> first to get a nice progress bar.</p>
