By this point, we've started our first agent and registered and queried one or more services on that agent. This showed how easy it is to use Consul, but didn't show how this could be extended to a scalable production service discovery infrastructure. On this page, we'll create our first real cluster with multiple members.
We've started our first agent and registered and queried a service on that agent. This showed how easy it is to use Consul but didn't show how this could be extended to a scalable, production-grade service discovery infrastructure. In this step, we'll create our first real cluster with multiple members.
---
---
# Consul Cluster
# Consul Cluster
By this point, we've started our first agent and registered and queried
We've started our first agent and registered and queried a service on that
one or more services on that agent. This showed how easy it is to use
agent. This showed how easy it is to use Consul but didn't show how this could
Consul, but didn't show how this could be extended to a scalable production
be extended to a scalable, production-grade service discovery infrastructure.
service discovery infrastructure. On this page, we'll create our first
In this step, we'll create our first real cluster with multiple members.
real cluster with multiple members.
When a Consul agent is started, it begins without knowledge of any other node,
When a Consul agent is started, it begins without knowledge of any other node:
and is an isolated cluster of one. To learn about other cluster members, the
it is an isolated cluster of one. To learn about other cluster members, the
agent must _join_ an existing cluster. To join an existing cluster, it only
agent must _join_ an existing cluster. To join an existing cluster, it only
needs to know about a _single_ existing member. After it joins, the agent will
needs to know about a _single_ existing member. After it joins, the agent will
gossip with this member and quickly discover the other members in the cluster.
gossip with this member and quickly discover the other members in the cluster.
@ -23,59 +22,97 @@ A Consul agent can join any other agent, not just agents in server mode.
## Starting the Agents
## Starting the Agents
To simulate a more realistic cluster, we are using a two node cluster in
To simulate a more realistic cluster, we will start a two node cluster via
Vagrant. The Vagrantfile can be found in the demo section of the repo
[Vagrant](https://www.vagrantup.com/). The Vagrantfile we will be using can
-> **Remember:** To join a cluster, a Consul agent only needs to
-> **Remember:** To join a cluster, a Consul agent only needs to
@ -83,16 +120,27 @@ learn about <em>one existing member</em>. After joining the cluster, the
agents gossip with each other to propagate full membership information.
agents gossip with each other to propagate full membership information.
## Auto-joining a Cluster on Start
## Auto-joining a Cluster on Start
Ideally whenever a new node is brought up in your datacenter, it should automatically join the Consul cluster without human intervention. To accomplish this, you can use [Atlas by HashiCorp](https://atlas.hashicorp.com?utm_source=oss&utm_medium=getting-started-join&utm_campaign=consul) and the [`-atlas-join` flag](/docs/agent/options.html#_atlas_join). An example configuration is shown below:
Ideally, whenever a new node is brought up in your datacenter, it should
automatically join the Consul cluster without human intervention. To
accomplish this, you can use
[Atlas by HashiCorp](https://atlas.hashicorp.com?utm_source=oss&utm_medium=getting-started-join&utm_campaign=consul)
and the [`-atlas-join` flag](/docs/agent/options.html#_atlas_join).
An example configuration is shown below:
```text
```text
$ consul agent -atlas-join \
$ consul agent -atlas-join \
-atlas=ATLAS_USERNAME/infrastructure \
-atlas=ATLAS_USERNAME/infrastructure \
-atlas-token="YOUR_ATLAS_TOKEN"
-atlas-token="YOUR_ATLAS_TOKEN"
```
```
To get an Atlas username and token, [create an account here](https://atlas.hashicorp.com/account/new?utm_source=oss&utm_medium=getting-started-join&utm_campaign=consul) and replace the respective values in your Consul configuration with your credentials. Now whenever a new node comes up with a Consul agent, it automatically joins your Consul cluster without any hardcoded configurations.
To get an Atlas username and token,
[create an account](https://atlas.hashicorp.com/account/new?utm_source=oss&utm_medium=getting-started-join&utm_campaign=consul)
Alternatively, you can use the [`-join` flag](http://www.consul.io/docs/agent/options.html#_join)
and replace the respective values in your Consul configuration with your
credentials. Now, whenever a new node comes up with a Consul agent, it
will automatically join your Consul cluster without any hardcoded