How to Setup and Configure Consul Agent On Client Mode

In our last consul post, we have explained the steps to setup up a multi-node consul cluster which runs on server more.

If you want to use consul services for your application on a server, you need to set up a consul agent on the client mode to talk to the consul cluster. A consul client agent is also a member of the system which can obtain the configurations present in the consul cluster.

In this post, we will look into the steps involved in running a consul agent on client mode for querying and retrieving services and information from the consul servers.

Install & Configure Consul Agent On Client Mode

Step 1: Update the package repositories and install unzip.

For RHEL/Centos,

For Ubuntu,

Step 2: Head over to consul downloads page. and get the link for Linux 64 bit.

Step 3: Download the consul binary to /opt directory.

Step 4: Unzip consul binary.

Step 5: Move consul executable to /usr/bin directory to be accessible system-wide. You can also move it a location which is in your system path.

Step 6: Verify the consul executable by executing the consul command. It should list the available commands.

Step 7: Create consul config directories.

Step 9: Create a consul config file.

Copy the following config content to the config.json file. You should have the value of encrypt which was used during the consul server configuration. If you don’t have this value, you can get it from the consul server from /var/consul/serf/local.keyring file. Also, provide the correct datacenter value available in the consul server

Step 11: Create a consul client service file.

Copy the following contents

Step 12: Reload system daemon.

Step 13: Start & check the status of consul client service.

Step 14: Check the consul members using the following command.

You should see your client node in your list of members. It will be of type client. The server cluster members will be of type server.

consul list client members

Query Services & Key Value Pairs From Consul Server

Now that we have successfully configured the client, lets run some checks by retrieving data from the consul server.

List All Available Services

Method 1: Using consul command

Method 2: Using API

Method 3: Using DNS query. Here you need to specify your service name to get the details.

Query key Values From Consul Client

Lets list a key named backend recursively,

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.