<p>I have a deployment (A pods) with a Service and HorizontalPodAutoscaler attached. I want to be able to control the scale down process and do some cleanup before the pod shutdown. Problem is, the cleanup can take a lot of time and for it to complete some other service (B pods) should be able to access the pod trying to shut down.</p>

<p>To accomplish this I set the deployment A to have a long <code>spec.terminationGracePeriodSeconds</code> value. When A pod gets the SIGTERM it starts finishing up and closing the process when it's done.</p>

<p>From the point pod A get the SIGTERM it is no longer receives connections from pod B because the service removes it's IP from the endpoint - making it impossible for pod A to finish it's cleanup.</p>

<p>Tried using ClusterIP and Headless services, both acts the same.</p>

<p>How can I make the service continue sending traffic to pod A even after it got the SIGTERM? I don't mind requests from B pods getting errors when trying to get to A pods.</p>

Idan
<p>There is no way to do that because of the termination process design.</p>

<p>Here is the extract from the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods" rel="nofollow noreferrer">documentation</a> of the termination process:</p>

<ol>
<li><p>User sends command to delete Pod, with default grace period (30s)</p></li>
<li><p>The Pod in the API server is updated with the time beyond which the Pod is considered “dead” along with the grace period.</p></li>
<li>Pod shows up as “Terminating” when listed in client commands</li>
<li><p>(simultaneous with 3) When the Kubelet sees that a Pod has been marked as terminating because the time in 2 has been set, it begins the pod shutdown process.</p>

<ol>
<li>If the pod has defined a preStop hook, it is invoked inside of the pod. If the preStop hook is still running after the grace period expires, step 2 is then invoked with a small (2 second) extended grace period.</li>
<li>The processes in the Pod are sent the TERM signal.</li>
</ol></li>
<li><p>(simultaneous with 3) <strong>Pod is removed from endpoints list for service, and are no longer considered part of the set of running pods for replication controllers. Pods that shutdown slowly can continue to serve traffic as load balancers (like the service proxy) remove them from their rotations.</strong></p></li>
<li>When the grace period expires, any processes still running in the Pod are killed with SIGKILL.</li>
<li>The Kubelet will finish deleting the Pod on the API server by setting grace period 0 (immediate deletion). The Pod disappears from the API and is no longer visible from the client.</li>
</ol>

<p>So, the Pod will be deregistered in the Service while resolving 'SIGTERM' signal and you have no options to avoid it.</p>
