title: Fetch logs for killed docker container in kubernetes
body: <p>A simplified version of the code</p>
  
  <pre><code>trap 'rm /tmp/not_done; echo "trap command got executed"; sleep 10' SIGTERM
  
  wait_sigterm() {
  
    touch /tmp/not_done
    while [ -f /tmp/not_done ]
    do
        sleep 60 &amp;
        wait $!  
    done
  }
  
  wait_sigterm
  </code></pre>
  
  <p>How can I make sure trap command got executed?</p>
  
  <p>One way would be if I can get access to the logs of the killed container and check for my echo message.</p>
  
  <p>I tried getting the logs (kubectl -n namespace-name logs pod-name container-name) in a while loop, so that I would be able to pick the last written logs till the container is alive.</p>
  
  <p>But the echo message was not present.
  My guess is logs are not written once we kill the container or maybe something else.
  Is there any way I can get the logs of a killed container or test the above scenario?</p>