<p>I wrote a <code>readiness_probe</code> for my pod by using a bash script. Readiness probe failed with Reason: Unhealthy but when I manually get in to the pod and run this command <code>/bin/bash -c health=$(curl -s -o /dev/null --write-out &quot;%{http_code}&quot; http://localhost:8080/api/v2/ping); if [[ $health -ne 401 ]]; then exit 1; fi</code> bash script exits with code 0.
What could be the reason? I am attaching the code and the error below.</p>
<p><strong>Edit:</strong> Found out that the health variable is set to 000 which means timeout in for bash script.</p>
<pre><code>readinessProbe:
  exec:
    command:
    - /bin/bash
    - '-c'
    - |-
      health=$(curl -s -o /dev/null --write-out &quot;%{http_code}&quot; http://localhost:8080/api/v2/ping);
      if [[ $health -ne 401 ]]; then exit 1; fi
</code></pre>
<p>&quot;kubectl describe pod {pod_name}&quot; result:</p>
<pre><code>Name:         rustici-engine-54cbc97c88-5tg8s
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Tue, 12 Jul 2022 18:39:08 +0200
Labels:       app.kubernetes.io/name=rustici-engine
              pod-template-hash=54cbc97c88
Annotations:  &lt;none&gt;
Status:       Running
IP:           172.17.0.5
IPs:
  IP:           172.17.0.5
Controlled By:  ReplicaSet/rustici-engine-54cbc97c88
Containers:
  rustici-engine:
    Container ID:   docker://f7efffe6fc167e52f913ec117a4d78e62b326d8f5b24bfabc1916b5f20ed887c
    Image:          batupaksoy/rustici-engine:singletenant
    Image ID:       docker-pullable://batupaksoy/rustici-engine@sha256:d3cf985c400c0351f5b5b10c4d294d48fedfd2bb2ddc7c06a20c1a85d5d1ae11
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 12 Jul 2022 18:39:12 +0200
    Ready:          False
    Restart Count:  0
    Limits:
      memory:  350Mi
    Requests:
      memory:  350Mi
    Liveness:  exec [/bin/bash -c health=$(curl -s -o /dev/null --write-out &quot;%{http_code}&quot; http://localhost:8080/api/v2/ping);
if [[ $health -ne 401 ]]; then exit 1; else exit 0; echo $health; fi] delay=10s timeout=5s period=10s #success=1 #failure=20
    Readiness:  exec [/bin/bash -c health=$(curl -s -o /dev/null --write-out &quot;%{http_code}&quot; http://localhost:8080/api/v2/ping);
if [[ $health -ne 401 ]]; then exit 1; else exit 0; echo $health; fi] delay=10s timeout=5s period=10s #success=1 #failure=10
    Environment:  &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-whb8d (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-whb8d:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       &lt;nil&gt;
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              &lt;none&gt;
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age   From               Message
  ----     ------     ----  ----               -------
  Normal   Scheduled  24s   default-scheduler  Successfully assigned default/rustici-engine-54cbc97c88-5tg8s to minikube
  Normal   Pulling    23s   kubelet            Pulling image &quot;batupaksoy/rustici-engine:singletenant&quot;
  Normal   Pulled     21s   kubelet            Successfully pulled image &quot;batupaksoy/rustici-engine:singletenant&quot; in 1.775919851s
  Normal   Created    21s   kubelet            Created container rustici-engine
  Normal   Started    20s   kubelet            Started container rustici-engine
  Warning  Unhealthy  4s    kubelet            Readiness probe failed:
  Warning  Unhealthy  4s    kubelet            Liveness probe failed:
</code></pre>

batupaksoy
<p>The probe could be failing because it is facing performance issues or slow startup. To troubleshoot this issue, you will need to check that the  probe doesn’t start until the app is up and running in your pod. Perhaps you will need to increase the <code>Timeout of the Readiness Probe</code>, as well as the <code>Timeout of the Liveness Probe</code>, like in the following example:</p>
<pre><code>readinessProbe:
          initialDelaySeconds: 10
          periodSeconds: 2
          timeoutSeconds: 10
</code></pre>
<p>You can find more details about how to configure the Readlines Probe and Liveness Probe in this <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/" rel="nofollow noreferrer">link</a>.</p>
