<p>I have been trying to get prestop to run a script before the pod terminates (to prolong the termination until the current job has finished), but command doesn't seem to be executing the commands. I've temporarily added an echo command, which i would expect to see in kubectl logs for the pod, i can't see this either.</p>
<p>This is part of the (otherwise working) deployment spec:</p>
<pre><code>      containers:
        - name: file-blast-app
          image:  my_image:stuff
          imagePullPolicy: Always
          lifecycle:
            preStop:
              exec:
                command: [&quot;echo&quot;,&quot;PRE STOP!&quot;]
</code></pre>
<p>Does anyone know why this would not be working and if i'm correct to expect the logs from hook in kubectl logs for the pod?</p>

Happy Machine
<p>You forgot to mention the shell through which you want this command to be executed.</p>
<p>Try using the following in your YAML.</p>
<pre><code>  containers:
    - name: file-blast-app
      image:  my_image:stuff
      imagePullPolicy: Always
      lifecycle:
        preStop:
          exec:
            command: [&quot;/bin/sh&quot;,&quot;-c&quot;,&quot;echo PRE STOP!&quot;]
</code></pre>
<p>Also, one thing to note is that a preStop hook only gets executed when a pod is terminated, and not when it is completed. You can read more on this <a href="https://github.com/kubernetes/kubernetes/issues/55807" rel="nofollow noreferrer">here</a>.</p>
<p>You can also refer to the K8S official documentation for lifecycle hooks <a href="https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/" rel="nofollow noreferrer">here</a>.</p>
