How to expose mongo containers to outside of the overlay network?

11/17/2019

I am running a mongodb replica set as containers in Mesos cluster ( My question also applied to k8s/swarm). The replica set can be initialized using DNS or container IPs. But, both DNS or container IPs can be accessed only in the overlay network of the Mesos cluster. Now, users want to access the mongo replica set from outside the Mesos/K8s cluster, how can they achieve this through an ingress/marathon-lb?

Not to consider HostPort here, because only the ingress/lb nodes are exposed to the public network.

-- Haoyuan Ge
docker
kubernetes
mesos
mongodb

1 Answer

11/18/2019

Ingress controller is using HTTP and it does not support TCP. MongoDB require regular TCP/IP socket.

There are two other ways to achieve that:

  • You can useNodePort or Loadbalancer service. If this runs on cloud then you can use loadbalancer, otherwise use NodePort. More information about services can be found here.
  • Alternatively you could use nginx ingress controller

Both solution are explained in this Mongodb tutorial

-- acid_fuji
Source: StackOverflow