<p>I am using below example to test postStart and preStop hooks.</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: aaaa
  labels:
    wwww: qqqq
spec:
  containers:
  - name: adassa
    image: nginx:1.10.1
    lifecycle:
      postStart:
        exec:
          command: ['bash', '-c', 'echo 11111111']
      preStop:
        exec:
          command: ['bash', '-c', 'echo 2222222']
</code></pre>
<p>My pod was successfully created, but later when I tried to check the hooks output using <code>kubectl logs aaaa -c adassa</code> and <code>kubectl logs aaaa</code> then there were no logs.</p>
<p>I tried but not able to pinpoint the issue. I thought maybe shell issue, so I changed <code>bash</code> to <code>sh</code> but after this even Pod was not created.</p>
<p>Anyone has any idea what is wrong here?</p>

hagrawal7777
<p><strong>PostStart event:</strong></p>
<p>The echo output is inside the container scope so it does not show/log anything.
For executing a command i use:</p>
<blockquote>
<p>command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;echo 11111111&gt; /tmp/message&quot;]</p>
</blockquote>
<p>There are several logging approaches however writing on a file as above is a simple example and for testing purposes.</p>
<p>Once you create a pod, execute interactive to get a shell and finally check if lifecycle trigger wrote on the sample file this way.</p>
<blockquote>
<p>kubectl exec -it aaaa -- /bin/bash</p>
<p>cat /tmp/message</p>
</blockquote>
<p>You should get:</p>
<blockquote>
<p>11111111</p>
</blockquote>
<p>Refer to <a href="https://logz.io/blog/a-practical-guide-to-kubernetes-logging/" rel="nofollow noreferrer">this</a> guide for different logging approaches, think about a 3rd party</p>
