<p>What happens when Kubernetes <code>readiness-probe</code> returns false? Does Kubernetes restart that pod after timeout? How long Kubernetes waits for readiness?</p>

J.J. Beam
<p>Readiness probe doesn't restart the pod/container, readiness probe determines that the container is ready to serve traffic. If the container is probed and considered not &quot;ready&quot;, the container will be removed from the endpoints and traffic wont be sent to it, until it is ready again.</p>
<p>[1] <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes</a></p>
<p>[2] <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes</a></p>
<p>[3] <code>kubectl explain pod.spec.containers.readinessProbe</code></p>
<pre><code>KIND:     Pod
VERSION:  v1

RESOURCE: readinessProbe &lt;Object&gt;

DESCRIPTION:
     Periodic probe of container service readiness. Container will be removed
     from service endpoints if the probe fails. Cannot be updated. More info:
     https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

     Probe describes a health check to be performed against a container to
     determine whether it is alive or ready to receive traffic.

FIELDS:
   exec &lt;Object&gt;
     One and only one of the following should be specified. Exec specifies the
     action to take.

   failureThreshold &lt;integer&gt;
     Minimum consecutive failures for the probe to be considered failed after
     having succeeded. Defaults to 3. Minimum value is 1.

   httpGet  &lt;Object&gt;
     HTTPGet specifies the http request to perform.

   initialDelaySeconds  &lt;integer&gt;
     Number of seconds after the container has started before liveness probes
     are initiated. More info:
     https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes

   periodSeconds    &lt;integer&gt;
     How often (in seconds) to perform the probe. Default to 10 seconds. Minimum
     value is 1.

   successThreshold &lt;integer&gt;
     Minimum consecutive successes for the probe to be considered successful
     after having failed. Defaults to 1. Must be 1 for liveness and startup.
     Minimum value is 1.

   tcpSocket    &lt;Object&gt;
     TCPSocket specifies an action involving a TCP port. TCP hooks not yet
     supported

   timeoutSeconds   &lt;integer&gt;
     Number of seconds after which the probe times out. Defaults to 1 second.
     Minimum value is 1. More info:
     https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes
</code></pre>
<p>Let's use the default readiness probe from the documentation:</p>
<pre><code>cat pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
    readinessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
</code></pre>
<p>To perform a probe, the kubelet executes the command cat /tmp/healthy in the target container. If the command succeeds, it returns 0, then the container is ready and can &quot;serve&quot;. if the command returns anything but 0, container is not healthy.</p>
<p>Since this file doesn't exist in the container from the start, when the pod starts, it is going to be very unhealthy.</p>
<pre><code>date &amp;&amp; k get pods nginx
Thu  2 Dec 2021 19:08:43 AST
NAME    READY   STATUS    RESTARTS   AGE
nginx   0/1     Running   0          66s
</code></pre>
<p>now, lets exec into it and create the file, so that the command succeeds.</p>
<pre><code>k exec -it nginx -- bash
root@nginx:/# touch /tmp/healthy
root@nginx:/# exit
exit
</code></pre>
<p>checking again:</p>
<pre><code>date &amp;&amp; k get pods nginx
Thu  2 Dec 2021 19:09:26 AST
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          110s
</code></pre>
<p>removing again:</p>
<pre><code>k exec -it nginx -- bash
root@nginx:/# rm /tmp/healthy
root@nginx:/# exit
exit
</code></pre>
<p>checking:</p>
<pre><code>date &amp;&amp; k get pods nginx
Thu  2 Dec 2021 19:09:53 AST
NAME    READY   STATUS    RESTARTS   AGE
nginx   0/1     Running   0          2m17s
</code></pre>
