<p>My Application stops gracefully when receiving a SIGTERM. graceful-stop operation is deleting a znode in the ZooKeeper.</p>
<p>But what I try is to automatically terminate a process gracefully before the Kubernetes evicts my pod.</p>
<p>I want to set prestop hook to &quot;kill 1&quot; to make a graceful-stop before the pod is evicted.</p>
<p>I'm not expecting prestop hook will work in all cases, but I think, this way I'll have some assurance.</p>
<p>I wonder if my idea is feasible.</p>

Park Beomsu
<p>Yes <code>preStop</code> is possible - and covers your use case. Here's the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/" rel="nofollow noreferrer">k8s docs</a> example:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: lifecycle-demo
spec:
  containers:
  - name: lifecycle-demo-container
    image: nginx
    lifecycle:
      postStart:
        exec:
          command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;echo Hello from the postStart handler &gt; /usr/share/message&quot;]
      preStop:
        exec:
          command: [&quot;/bin/sh&quot;,&quot;-c&quot;,&quot;nginx -s quit; while killall -0 nginx; do sleep 1; done&quot;]
</code></pre>
