Search code examples
servicebroadcastmulticastservice-discoveryconsul

Consul: join without knowing IP of existing members


For joining a new agent into a group of consul members, one needs to know the IP of at least one existing member. I have to support a scenario in which I do not know an IP of any existing group members. Human intervention is not possible in this situation as a the service discovery has to run completely automatically.

My idea to solve this: I could send a message via broadcast or multicast to other computers in the network. Every computer hosts a custom service that I will implement. That service replies to this special broadcast/multicast message (e.g.: "Looking for existing cluster members") with the IP address to which the consul is listening. The service will then get one or more replies from the network and use one of the IP addresses to join the cluster.

Does anyone have a better idea to solve this problem? Are there any existing libraries to solve this?


Solution

  • Hashicorp provides a free service as part of Atlas to do just that: https://www.consul.io/docs/guides/atlas.html

    The other easier ways to do it without a custom service:

    • Expose Consul servers in a third-party DNS that the servers can access before they join the Consul cluster. Alternatively, have a http service that is exposed that returns an IP to join to and use curl or something to get the IP. Keep the IP updated using Consul.
    • If you're running in AWS or a similar service that provides metadata about machines, use that service to tag your Consul boxes and then use the service's query functionality to do something like "find servers that have tag Consul and are running" and pass them to -join.