<p>We are using Spring Boot in Kubernetes in our project. Recently we decided to add graceful shutdown for our application in order to ensure seamless deployments and make sure no requests are failed during pod terminations for whatever reason.
Even though Spring Boot provides graceful shutdown, it seems there is still a probability that requests may fail due to the fact that Kubernetes starts removing a pod from endpoints and sends the SIGTERM signal to the pod at the same time in parallel.
Quote from kubernetes <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/" rel="nofollow noreferrer">documentation</a>:</p>
<blockquote>
<p>At the same time as the kubelet is starting graceful shutdown, the control plane removes that shutting-down Pod from Endpoints (and, if enabled, EndpointSlice) objects where these represent a Service with a configured selector.</p>
</blockquote>
<p>This is aldso described in more detail <a href="https://youtu.be/wBtUIkMgzU8?t=3063" rel="nofollow noreferrer">here</a>. The solution is provided there as well, which is</p>
<blockquote>
<p>you can add a sleep in a preStop hook of the pod spec and, of course, <em><strong>configure that sleep to be whatever makes sense for your use case</strong></em> :</p>
</blockquote>
<p><a href="https://i.stack.imgur.com/IjAcq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IjAcq.png" alt="enter image description here" /></a></p>
<p>In the example provided this sleep is configured to be 10 seconds, but I'm wondering what is the reasonable value for that, so the pod's termination is not unnecessarily delayed?</p>
<p>Thanks.</p>

ZeeG
<p>It seems like this might be up to your preferences but it looks like the 5-10 seconds sleep is a recommended range:</p>
<blockquote>
<p>In “Kubernetes in Action”, Lukša recommends 5–10 seconds
<a href="https://blog.gruntwork.io/delaying-shutdown-to-wait-for-pod-deletion-propagation-445f779a8304" rel="nofollow noreferrer">https://blog.gruntwork.io/delaying-shutdown-to-wait-for-pod-deletion-propagation-445f779a8304</a></p>
</blockquote>
