title: Access mongo service running on host OS from application in kubernetes cluster
body: <p>I have a small on premise kubernetes cluster setup with one master node(master1: 192.168.122.4) and one worker node (worker1: 192.168.122.5). Worker1 has a single replica set mongo instance running on the bare metal OS not in k8s cluster. I can access the mongodb in the following ways outside of the k8s cluster (NOTE: all hostnames are resolvable from dns running on master1)</p>
  <p>From master1:</p>
  <pre><code>mongo --host 192.168.122.5
  mongo --host worker1
  </code></pre>
  <p>From worker1:</p>
  <pre><code>mongo (which connects to 127.0.0.1:27017)
  mongo --host 192.168.122.5
  mongo --host worker1
  </code></pre>
  <p>I also have an application running in the k8s cluster which gets scheduled to worker1. Below is the pod specs:</p>
  <pre><code>apiVersion: v1
  kind: Pod
  metadata:
    name: test-app
  spec: 
    dnsConfig: 
      nameservers:
      - 192.168.122.4
      searches:
      - test.123.domain
    containers:
    - name: test-app
      image: registrysvc:5000/test-image:latest
      imagePullPolicy: Always
  </code></pre>
  <p>I have tried the below and it does not work. I am able to run nslookup and get the correct IP back, but I cannot connect to mongo:</p>
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: mongo
    namespace: default
  spec:
    clusterIP: None
    ports:
    - name: mongo
      port: 27017
      protocol: TCP
  ---
  apiVersion: v1
  kind: Endpoints
  metadata:
    name: mongo
    namespace: default
  subsets:
    - addresses:
        - ip: 192.168.122.5 
      ports:
        - port: 27017
          name: mongo
          protocol: TCP
  </code></pre>
  <p>Is there a way to connect to the mongo instance running on the host OS from the test-app running in the k8s cluster on the same host? I essentially want to be able to run <code>mongo</code> or <code>mongo --host xyz</code> to connect to the instance.</p>
  <p>More info about cluster:
  Kubernetes version 1.20.5
  Using flannel version 0.13.0 as CNI</p>