<p>i defined a memory limit for one of my pods and a preStop hook that the running service can be gracefully shutdown, but the defined method for the preStop hook doesn't get exectuted when the pod got restarted after the memory limit got reached.</p>
<pre><code>        lifecycle:
          preStop:
            exec:
              command:
              - /bin/sh
              - -c
              - echo 'Hi from the postStart handler' &gt;&gt; /app/public/system/test
        name: my_pod
        resources:
          limits:
            memory: 800Mi
          requests:
            memory: 500Mi
</code></pre>
<p>Any suggestion how to gracefully shutdown a service when it got killed by a memory limit?</p>
<p>if i kill the pod manually then it works as expected, but it looks like that the OOMKilled error does't use the lifecycle hook.</p>

stereosupersonic
<p>OOM killed is not a graceful stop of the pod. Therefore, the prestop hook would not run. I suggest configuring the application to fail the health check when the memory limit is about to be reached.</p>
