Alternative way to expose Mongo replicaset

Hello @vhphan ,

this is good question indeed.

I see multiple ways here:

  1. Run a cluster with one shard. User experience would be the same, but you would need more resources on kubernetes for config server replica set and mongos. This was our thought process when we introduced mongos first - single shard to save resources on load balancers. In 1.6.0 Release notes:

K8SPSMDB-273: Add support for mongos service to expose a single shard of a MongoDB cluster through one entry point instead of provisioning a load-balancer per replica set node. In the following release, we will add support for multiple shards.

  1. You can put some TCP ingress service as a front and proxy traffic to MongoDB replica set nodes. You will need to configure ingress to point to the nodes yourself.

So you will have a mapping of ports. Port 33333 on NLB, will translate to Replica Set #1 Node #1 for example. I did something similar back then, but not for mongo.

  1. I also used this tool in the past: GitHub - DevFactory/smartnat: Kubernetes controller to expose Services with TCP/UDP

It is no longer developed, but it was created specifically to lower the cost. It requires you to run a dedicated EC2 instance with multiple network interfaces (ENIs) and IP-addresses. Then it hooks up with Kubernetes and serves as a TCP proxy for traffic. So similar to (2), but a bit more complex :slight_smile:

Let me know if it helps.

3 Likes