<p>We are trying to get the logs of pods after multiple restarts but we dont want to use any external solution like efk.</p>
<p>i tried below config but its not working. does the below cmd run on the pod or it will run on node level</p>
<pre><code>lifecycle:
  preStop:
  exec:
       command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;kubectl logs appworks-0 &gt; /container-stoped.txt&quot;]

</code></pre>

Yugandhar Reddy
<blockquote>
<p>i tried below config but its not working. does the below cmd run on
the pod or it will run on node level</p>
</blockquote>
<p>it will run on the POD level, not on <strong>Node</strong> level</p>
<p>You can use the <strong>Hostpath</strong> in POD configuration</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:  
  - image: alpine
    name: test-container
    command: [&quot;tail&quot;]
    args: [&quot;-f&quot;, &quot;/dev/null&quot;] 
    volumeMounts:
    - mountPath: /host
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /
      type: Directory
</code></pre>
<p><strong>Hostpath</strong> will directly will create one Dir at the Node level and save logs over there, if you don't want this solution you can add your solution of <strong>lifecycle hook</strong> also however when you can directly write app logs to Host don't add lifecycle hook extra.</p>
<p><strong>Note</strong> : Make sure if your Node goes down <strong>hostpath</strong> or <strong>emptyDir</strong> logs you will miss.</p>
