<p>This problem only arises on a cluster created with default Minikube settings, but not on a remote cluster created via Kops.</p>
<p>I run this setup on a Minikube cluster in a virtual machine. I have a Pod running MongoDB in my namespace and a service pointing to it:</p>
<pre><code>kind: Deployment
apiVersion: apps/v1
metadata:
  name: mongo
  namespace: platform
  labels:
    app: mongo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo
  template:
    metadata:
      labels:
        app: mongo
    spec:
      containers:
        - name: mongo
          image: mongo
          env:
          - name: MONGO_INITDB_ROOT_USERNAME
            value: root
          - name: MONGO_INITDB_ROOT_PASSWORD
            value: password

---
apiVersion: v1
kind: Service
metadata:
  name: mongo
  namespace: platform
spec:
  selector:
    app: mongo
  ports:
    - protocol: TCP
      port: 27017
</code></pre>
<p>When I run a shell inside a mongo container, I can connect to the database with</p>
<pre><code>mongo mongodb://root:password@localhost:27017
</code></pre>
<p>but it does not work with</p>
<pre><code>$ mongo mongodb://root:password@mongo:27017
MongoDB shell version v4.4.1
connecting to: mongodb://mongo:27017/?compressors=disabled&amp;gssapiServiceName=mongodb
Error: couldn't connect to server mongo:27017, connection attempt failed: SocketException: Error connecting to mongo:27017 (10.110.155.65:27017) :: caused by :: Connection timed out :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1
</code></pre>
<p>I checked the service and it points to the correct address:</p>
<pre><code>$ kubectl describe service mongo --namespace platform
Name:              mongo
Namespace:         platform
Labels:            &lt;none&gt;
Annotations:       &lt;none&gt;
Selector:          app=mongo
Type:              ClusterIP
IP:                10.110.155.65
Port:              &lt;unset&gt;  27017/TCP
TargetPort:        27017/TCP
Endpoints:         172.17.0.9:27017
Session Affinity:  None
Events:            &lt;none&gt;
$ kubectl describe pod mongo-6c79f887-5khnc | grep IP   
IP:           172.17.0.9
</code></pre>
<p>And using this endpoint directly works, too:</p>
<pre><code>mongo mongodb://root:password@172.17.0.9:27017
</code></pre>
<p>As a sidenote, I have other pods+services running webservers in the same namespace, which work as expected through the service.</p>
<h3>Addition</h3>
<p>I run the <code>mongo ...</code> connection commands from within the MongoDB container/pod. I also tried all these connection commands from other pods inside the same namespace. Always with the same result: Using the IP works, using <code>mongo</code> for dns resolution does not work.</p>
<p>As a test, I replicated the exact same pod/service configuration but with an nginx server instead of mongodb:</p>
<pre><code>...
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: nginx
  namespace: debug-mongo
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: debug-mongo
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
</code></pre>
<p>And <code>curl nginx:80</code> returns the default nginx page successfully.</p>

Natjo
<p>Okay forgot what I said before. You need to set your services clusterIP to none.</p>
<pre><code>spec:
  clusterIP: None
</code></pre>
<p>K8s service with cluster ip acts like loadbalancer and mongo cant work like that i suppose.</p>
