<p>I have a spring boot camel application that processes messages on activeMq. however every once in a while, the ready probe fails and restarts the pod. Now thats fine, but then i get the applciation loggin out Inflight messages constantly and it gets into a restart cyclem due to ready probe constantly failing.</p>

<p>Is it possible to have kubernets allow the spring/camel app to gracefully shut down or consume any messages on the queue?</p>

user1555190
<p>Using <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks" rel="nofollow noreferrer">Container hooks</a>, you can setup <code>prestop</code> that can look as follows:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: lifecycle-demo
spec:
  containers:
  - name: lifecycle-demo-container
    image: nginx
    lifecycle:
      postStart:
        exec:
          command: ["/bin/sh", "-c", "echo Hello from the postStart handler &gt; /usr/share/message"]
      preStop:
        exec:
          command: ["/usr/sbin/nginx","-s","quit"]
</code></pre>

<blockquote>
  <p>This hook is called immediately before a container is terminated. It is blocking, meaning it is synchronous, so it must complete before the call to delete the container can be sent. No parameters are passed to the handler.</p>
</blockquote>

<p>You can follow the flow on <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#termination-of-pods" rel="nofollow noreferrer">Termination of Pods</a></p>

<blockquote>
  <ol>
  <li>User sends command to delete Pod, with default grace period (30s)</li>
  <li>The Pod in the API server is updated with the time beyond which the Pod is considered “dead” along with the grace period.</li>
  <li>Pod shows up as “Terminating” when listed in client commands</li>
  <li>(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.
  
  <ol>
  <li>If the pod has defined a  <a href="https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#hook-details" rel="nofollow noreferrer">preStop hook</a>, it is invoked inside of the pod. If the  <code>preStop</code>  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>(simultaneous with 3) 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 cannot continue to serve traffic as load balancers (like the service proxy) remove them from their rotations.</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>
</blockquote>
