Skip to main content

Documentation Index

Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt

Use this file to discover all available pages before exploring further.

In this section, we reviewed the essential steps to install, configure, and operate Consul agents in both server and client modes.

Key Takeaways

TaskDescriptionExample/Command
Agent StartupLaunch Consul from the CLI or via a JSON/HCL config fileconsul agent -dev -bind 192.168.1.10
Configuration FormatsDefine common settings, server/client roles, and register servicesHCL or JSON snippets
Network Binding & PortsSet bind_addr, and customize RPC, HTTP, and DNS port assignmentsbind_addr = "0.0.0.0"
Cluster Join & LeaveAdd nodes with consul join and gracefully remove them using consul leaveconsul join 10.0.0.1
Before restarting agents, validate your configuration:
consul validate /path/to/config.hcl

1. Starting and Managing the Consul Process

You can start a Consul agent directly from the command line:
consul agent \
  -dev \
  -bind 192.168.1.10 \
  -config-dir /etc/consul.d
Or use an HCL/JSON configuration file (consul.hcl):
datacenter       = "dc1"
node_name        = "consul-server-1"
server           = true
bootstrap_expect = 3
bind_addr        = "0.0.0.0"

ports {
  http = 8500
  rpc  = 8400
  dns  = 8600
}

2. Interpreting Consul Agent Configurations

Both HCL and JSON support the same agent options.
Example HCL for a client agent registering a web service:
service {
  name = "web"
  port = 80
  tags = ["nginx", "frontend"]
}

3. Configuring Network Addresses and Ports

Fine-tune Consul network settings to optimize performance and security:
  • bind_addr: IP/interface for RPC, HTTP, DNS
  • advertise_addr: Publicly advertised address
  • ports.rpc, ports.http, ports.dns
bind_addr = "10.0.0.5"
advertise_addr = "203.0.113.10"

ports {
  http = 8500
  rpc  = 8400
  dns  = 8600
}

4. Agent Join and Leave Behaviors

Joining a Cluster

Use the consul join command to add a new node:
consul join 10.0.0.1 10.0.0.2

Graceful Leave

For clients and especially servers, remove nodes gracefully to maintain cluster health:
consul leave
Always drain and remove server nodes gracefully to avoid quorum loss.
Use consul leave rather than killing the process.

Next Steps

Move on to Objective 3: Service Discovery & Health Checking to learn how Consul automatically tracks and verifies service health.

Watch Video