<p>I am using a deployment of Spring Boot (typical micro-service web server deployment, with Gateway, separate authentication server, etc, fronted with a reverse proxy/load balancing nginx deployment). We orchestrate Docker containers with Kubernetes. We are preparing for production deployment and have recently started load testing, revealing some issues in the handling of these loads.</p>

<p>My issue is that when subjecting the server to high loads (here, performance testing with Gatling), the liveness probes return 503 errors, because of heavy load; this triggers a restart by Kubernetes.</p>

<p>Naturally, the liveness probe is important, but when the system starts dropping requests, the last thing we should do is to kill pods, which causes cascading failures by shifting load to the remaining pods.</p>

<p>This specific problem with the Spring Actuator health check is described <a href="https://stackoverflow.com/questions/50005849/kubernetes-liveness-reserve-threads-memory-for-a-specific-endpoint-with-spring">in this SO question</a>, and offers some hints, but the answers are not thorough. Specifically, the idea of using a liveness command (e.g. to check if the java process is running) seems to me inadequate, since it would miss actual down-time if the java process is running but there is some exception, or some missing resource (database, Kafka...)</p>

<ol>
<li>Is there a good guide for configuring production Spring on Kubernetes/Cloud deployments?</li>
<li>How do I deal with the specific issue of the liveness probe failing when subjected to high loads, does anyone have experience with this?</li>
</ol>

Alexandre Cassagne
<p><strong>Note:</strong> This is the answer provided by @AndyWilkinson and @ChinHuang on comments which @AlexandreCassagne stated that solved the issue:</p>
<blockquote>
<p>If a liveness probe indicates that the current level of traffic is overwhelming your app such that it cannot handle requests, trying to find a way to suppress that seems counter-productive to me. Do you have a readiness probe configured? When your app becomes overwhelmed, you probably want it to indicate that it is unable to handle traffic for a while. Once the load has dropped and it's recovered, it can then start handling traffic again without the need for a restart.</p>
<p>Also, a liveness probe should only care about a missing resource (database, Kafka, etc) if that resource is only used by a single instance. If multiple instances all access the resource and it goes down, all of the liveness probes will fail. This will cause cascading failures and restarts across your deployment. There's some guidance on this in the <a href="https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/reference/htmlsingle/#boot-features-application-availability" rel="nofollow noreferrer">Spring Boot 2.3 reference documentation.</a></p>
<p>Spring Boot 2.3 introduces <a href="https://spring.io/blog/2020/03/25/liveness-and-readiness-probes-with-spring-boot" rel="nofollow noreferrer">separate liveness and readiness probes</a>.</p>
</blockquote>
