<p>I try to restart the pod when an endpoint returns an HTTP 500 on the /health endpoint. The service, probe-pod, should never send traffic to the pod while it is failing.</p>
<ul>
<li>The application needs to has an endpoint /start, which will indicate if it can accept traffic by returning an HTTP 200. If the endpoint returns an HTTP 500, the application has not finished initialization</li>
<li>The application needs to have another endpoint /health that will indicate if the application is still working as expected by returning an HTTP 200. If the endpoint returns an HTTP 500 the application is no longer responsive.</li>
<li>The probes should use port 8080</li>
</ul>
<p>I know how the readiness and liveness probe works but how to connect their response base of output? I can't solve the first and second items. How could I test the solution? Could anyone help me?</p>

<blockquote>
<p>I try to restart the pod when an endpoint returns an HTTP 500 on the /health endpoint. The service, probe-pod, should never send traffic to the pod while it is failing.</p>
</blockquote>
<p>This is the default behavior in Kubernetes with readiness probes. If the probe is failing then the pod is not 'ready' and no service forwards traffic to that pod. You can control the responsiveness of this (with some performance penalties implications) with the <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#configure-probes" rel="nofollow noreferrer"><code>periodSeconds</code></a> option. For example, you can set it to 1 second to make sure that as soon as the probe fails it's taken out of the traffic pool.</p>
<p>In terms of Readiness, Liveness, and Startup probes they have an <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes" rel="nofollow noreferrer"><code>httpGet</code></a> mechanism. They consider everything status codes <code>200-399</code> as passing and everything else as failing but they don't allow you to control which status codes are 'Success' and which ones are 'Failure'.</p>
<p>If you'd like more control over the status code you can use the <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes" rel="nofollow noreferrer"><code>ExecAction</code></a> mechanism and just use a script like this:</p>
<pre class="lang-sh prettyprint-override"><code>CODE=`curl -s -o /dev/null -w '%{http_code}' http://www.example.org/`; if [ &quot;$CODE&quot; -ge 200 ] &amp;&amp; [ &quot;$CODE&quot; -le 399 ]; then exit 0; else exit 1; fi
</code></pre>
<p>In the above case, you have to make sure that <code>curl</code> is installed in you container.</p>
