<p>While running monogodb in kubernetes it gives following error:-</p>

<p>I tried to change image of mongodb</p>

<pre><code>Warning  Unhealthy  2m28s  kubelet, minikube  Readiness probe failed: MongoDB 
shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2019-06-08T15:25:01.774+0000 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6
exception: connect failed
 Warning  Unhealthy  2m17s  kubelet, minikube  Readiness probe failed: MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2019-06-08T15:25:12.008+0000 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:344:17
@(connect):2:6
exception: connect failed
</code></pre>

Ritesh Jhaggar
<p>I was observing the same error, once I've increased <code>initialDelaySeconds:</code> value to some higher number in <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-readiness-probes" rel="noreferrer">Readiness</a> probe spec inside deployment, the issue has gone and <code>mongodb</code> Pod has been spawned without error. Actually, it takes some time for docker to pull up <code>docker.io/bitnami/mongodb</code> image and initialize socket <code>mongodb</code> listener, therefore Readiness probe indicates issue while container process has not ready for network connections.</p>

<pre><code>    readinessProbe:
      exec:
        command:
        - mongo
        - --eval
        - db.adminCommand('ping')
      failureThreshold: 6
      initialDelaySeconds: 360
      periodSeconds: 10
      successThreshold: 1
      timeoutSeconds: 5
</code></pre>

<p>Meanwhile, you can check <code>mongodb</code> Pod for any inbound connection statuses or any relevant event.</p>

<p><code>kubectl logs &lt;mongodb-Pod-name&gt;</code></p>

<p>I've used <a href="https://github.com/helm/charts/tree/master/stable/mongodb" rel="noreferrer">stable/mongodb</a> Helm chart to deploy MongoDB and discovered the error similar to yours:</p>

<p><code>helm install --name mongodb stable/mongodb</code></p>

<blockquote>
  <p>Warning  Unhealthy               38m                kubelet,
  gke-helm-test-default-pool-efed557c-52tf  Readiness probe failed:
  MongoDB shell version v4.0.9 connecting to:
  mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
  2019-06-10T12:46:46.054+0000 E QUERY    [js] Error: couldn't connect
  to server 127.0.0.1:27017, connection attempt failed: SocketException:
  Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused
  : connect@src/mongo/shell/mongo.js:343:13 @(connect):2:6 exception:
  connect failed</p>
</blockquote>

<p>When I made some adjustment and gain <code>readinessProbe.initialDelaySeconds</code> from 5 sec to 360 sec, <code>mongodb</code> container run up without any failures.</p>

<pre><code>helm install --name mongodb stable/mongodb --set readinessProbe.initialDelaySeconds=360
</code></pre>
