Consul colliding ports example

Lets assume I have 3 pods that need to talk to eachother (like a mongodb replicaset, I know Im not suppose to use plain pods for that :slight_smile: ).

When I initiate a mongodb repliaset I do so like this (


This will not work with consul though since the mongodb container only talks over localhost to the injected envoy proxy.

But then I have todo someting like this:

I am forced to use different ports since the address is to go via the envoy proxy. This means the other replicas will need to bind to weird mongo ports like 27018 and 27019.

It would be nice if instead of 127.0.01 you could use some kind of dns name like the picture above.

I would like to have something like this:

Then the mongo-1 upstream could be

But there are port collisions and stuff here I get that, not sure if there is a good solution for this.

What I do now is basically bind my different mongos to ports like 27018 and 27019 but I would like to avoid this if possible.

Thanks in advance, have a great weekend!

nvm Im dumb… solved it

Hi @josvegit,

Would you be open to sharing your solution to this problem? It might be beneficial for others who come across this thread in the future.


1 Like

Yes ofc sorry.

My solution was simply registering the replicaset like this:

And then using upstreams like =>

Also had to add some intentions since I had enabled ACLS:

Now this is still a bit of an ugly solution. I would rather have had a statefulset but consul doesn’t seem to be able to route traffic to individual pods in a stateful set nicely. Or at least I have not gotten that to work. I commented on this issue on github.

But it does work.