Skip to content

Start the client agents

Chris edited this page Aug 31, 2016 · 17 revisions

Why client agents are important

Having client agents for both Nomad and Consul are essential. The purpose of the client agents is to automatically be able to communicate with the Nomad/Consul servers so that any requests to the client agent can be forwarded to the server.

As long as the client agents know the address of one running server on start up, they will automatically know the addresses of the server cluster. This is essential because now applications on different machines that want to talk to the server can just send a request to the local agent instead of having a hard coded server address and running the risk of not being able to contact the cluster if that specific server goes down. We will use this technique to set up our Consul and Nomad client agents.

Start the Consul client agent

On my second Ubuntu machine I'm first going to start up the local consul agent and activate some important features:
consul agent -data-dir="/tmp/consul" -ui -bind=<ip> -client=<ip>

  • consul agent starts the agent in client mode. Remember that adding -server starts the agent in server mode
  • -data-dir is here for the same reason we need it for the consul server agent
  • -ui isn't necessary, but it makes the agent listenable on a certain port that we can point our browser to and we end up seeing some really nice UI of statuses of our services, nodes, and key value store. By default, this address is http://127.0.0.1:8500/ui This will not work in our scenario. Keep reading as to why
  • -bind=<ip> also will attach the agent to the ip specified. This is required if there are multiple IPs found. Use the IP of the host machine this agent is on.
  • -client=<ip> is the key in making our Manticore system work. It functions the same way as -bind, only now ALL interactions with the agent must now be made on the IP address specified instead of local host (127.0.0.1). Use the same IP as in the -bind flag.

The -client flag

If you remember, our Consul server didn't set the -client flag and because of that we could run consul without any additional parameters. Now, in order to use the Consul API and the consul command you must append -rpc-addr=<ip>:8400 to all commands and when using the Consul API you use the address you put in the -client flag. For example, to access the UI when activated, you point your browser to http://<ip in -client flag>:8500/ui. The reason why we do this is because when we schedule docker containers we want the applications to be able to use the Consul API by talking to the local agent. But, the local host inside the docker container is different from the local host in the virtual machine, which is Consul's default address for using the API. Therefore, we specify an address that the container application can reach so that it can use the API.

Join the Consul client agent to the server

If you noticed when you started the agent, one of the logs tells you that there are no known Consul servers. Our agent needs a Consul server address so that it can connect to the entire cluster. To do this, run:
consul join -rpc-addr=<ip of this machine>:8400 <ip of the consul server agent>
If we didn't specify the -client flag then we could leave out the -rpc-addr flag.
If you see this message then you are good to go:
Successfully joined cluster by contacting 1 nodes.

Start the Nomad client agent

Similar to how we started the Nomad server agent, we will also use an HCL file to pass in configurations.

# The address the nomad agent will bind to
bind_addr="127.0.0.1" # Replace this with your machine's IP
log_level="DEBUG"

data_dir="/tmp/nomad"

consul {
    # Consul's Client agent Address. The Nomad agent connects to Consul through the running consul client agent
    address = "127.0.0.1:8500" # Keep port 8500, but replace with your machine's IP
}

# Client configuration
client {
    enabled = true
    # A list of Nomad servers to connect to. You only need one running server for this to work
    # Keep port 4647, but replace with the IP of the Nomad server
    servers = ["127.0.0.1:4647"] 
}

ports {
    # The port you use to communicate to the Nomad client agent over HTTP
    # If you don't have this then the default changes to 4646.
    http = 4646
}

Now run the agent, passing in the file above (assuming it's called client.hcl)
nomad agent -config client.hcl

Try running a nomad command. Don't forget to pass in the IP address of where Nomad is listening
nomad status -address=http://<ip of nomad client agent>:4646

If you made it this far then congratulations. You are ready to start running jobs.

Clone this wiki locally