Search code examples
consul

Finding Consul cluster for agents


So I have built a 3 node Consul cluster. Right now they are only represented by IP addresses. In reading the documentation it is unclear to me how I expose their location to others wanting to query it.

I could hard code the IP address of the current leader into the other agents, but that doesn't seem like the best idea. I could assign a DNS name to each node, but what if the leader changes due to network issues? Is that a problem? Does it matter which node I query/write to?

I guess I haven't read anywhere explaining this part of the cluster setup. When I launch a new system that needs to query the Consul cluster how do I automatically let it know where the Consul cluster is.


Solution

  • There is no escape from the fact that the clients needs to connect the masters and not vice versa.

    If you want to automate a boot process of an entire cluster there are few options:

    1. You can hard code the addresses of the masters - which should use static addresses (The clients can have dynamic IP addresses). This can be done on premise or even in cloud environments - look for AWS VPC documentation for example. This is the easiest approach.

    2. You can launch the masters first, and whenever a client boots you can provide him the IP addresses of the masters. In the cloud this can be automated using user data for example. This can also be automated by your IT automation tool like ansible for example. It requires some modification to the boot process as you will need to edit you client configuration on boot, however this will not limit you to hard code addresses. This approach will may slow down you cluster boot time since things can serial now. However if you will work hard enough this can be avoided (by launching all the cluster, and find a way to pass the masters ip addresses to the clients on run time, and only then start the consul process of the clients).

    I think that the most elegant is #1 though, but this depends on your needs.

    Any way, make sure that the IP addresses of the masters will not change after the cluster was initiated. Even after reboot. This is a bad practice.

    Also, it is better to pass all three ip addresses to the clients for high availability (if u chose 3 master configuration).