<p>What is the recommended way to gracefully kill a container and driver pods in kubernetes when an application fails or reaches an exception. Currently, when my application runs into an exception my pods and executors continue to run and I noticed that my container doesn't get killed unless an explicit exit 1 is used.For some reason my spark application doesn't cause an exit 1 status or sigterm signal to be sent to the container or pod.
Tried to add following to yaml specs based on recommendations but still not getting pod driver and executors to terminate:</p>

<pre><code>spec:
  terminationGracePeriodSeconds: 0
  driver:
    lifecycle:
      preStop:
        exec:
          command:
          - /bin/bash
          - -c
          - touch /var/run/killspark &amp;&amp; sleep 65
</code></pre>

horatio1701d
<p>The preStop LiveCycle hook you added won't have any effect, since it is only triggered </p>

<blockquote>
  <p>before a container is terminated due to an API request or management
  event such as liveness probe failure, preemption, resource contention
  and others</p>
</blockquote>

<p><a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/</a></p>

<p>I suspect, what you really have to figure out is <strong>why your container main process keeps running despite the exception</strong>. </p>
