<p>I have a kubernetes instalation with master and 1 node. </p>

<p>It is configured and everything is working very good. </p>

<pre><code>$ kubectl get pods

NAME          READY     STATUS    RESTARTS   AGE 
mantis-gfs    1/1       Running   1          22h 
mongodb-gfs   1/1       Running   0          14h
</code></pre>

<p>I exposed the pod mongodb-gfs:</p>

<pre><code>$ kubectl expose pod mongodb-gfs --port=27017 --external-ip=10.9.8.100 --name=mongodb --labels="env=development"
</code></pre>

<p>The extrnal IP 10.9.8.100 is the IP of the kubernetes master node</p>

<p>The service was created successfully.</p>

<pre><code>$ kubectl get services

NAME                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)     AGE
glusterfs-cluster   ClusterIP   10.111.96.254   &lt;none&gt;        1/TCP       23d
kubernetes          ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP     29d
mongodb             ClusterIP   10.100.149.90   10.9.8.100    27017/TCP   1m
</code></pre>

<p>Now i am able to access the mongo using:</p>

<pre><code>mongo 10.9.8.100:27017 
</code></pre>

<p>And here is the problem. It works some time, but some time not.
I connect once and i get the shell, i connect second time and get:</p>

<pre><code>$ mongo 10.9.8.100:27017

MongoDB shell version v3.4.17
connecting to: mongodb://10.9.8.100:27017/test
2018-11-01T09:27:23.524+0100 W NETWORK  [thread1] Failed to connect to 10.9.8.100:27017, in(checking socket for error after poll), reason: Connection refused
2018-11-01T09:27:23.524+0100 E QUERY    [thread1] Error: couldn't connect to server 10.9.8.100:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed
</code></pre>

<p>Then i try again and it works, try again it works, try again it not works...</p>

<p>Any clues what may cause the problem?</p>

<p>I found the problem and the solution. The problem was, the pod definition. For both pods: mongodb-gfs and mantis-gfs i have the same label settings. Then i exposed services with the same label="env=development". In this case the traffic that i expected to go always to one pod was "loadbalanced" to one or other pod (they have the same label) of different types. </p>

<p>Changing the label in the mongodb-gfs pod definition solved the problem with connection issues.</p>
