Skip to main content
In this lesson, we’ll explore how to configure the Consul agent using either JSON or HCL (HashiCorp Configuration Language). Proper agent configuration determines whether Consul runs in server or client mode and controls critical network, security, and cluster membership settings.

Sample JSON Configuration

Below is a baseline JSON file for a Consul server in us-east-1. You can also write this in HCL; refer to the Consul Configuration Documentation for HCL examples.
Additional examples and a hands-on practice lab follow this section.

Understanding Configuration Sources

You can provide configuration through:
  • JSON/HCL files
  • Command-line flags (e.g., -server, -bootstrap-expect)
  • Environment variables prefixed with CONSUL_
Environment variables are useful for overrides in containerized or CI/CD environments. For complex configurations, maintain a single JSON or HCL file.

Key Options in a Server Configuration File

Below is a summary of the most common server directives. Adjust these values to match your deployment topology and security requirements.
Keep your gossip encryption key (encrypt) confidential. If exposed, rotate it immediately using consul keygen and reconfigure all agents.
The image is a guide on interpreting a Consul agent configuration, listing key options in a server configuration file, such as server, datacenter, node, and others. It emphasizes that environment variables cannot configure the Consul client.
Depending on your environment, you may also configure: ACLs (acl block), syslog integration (enable_syslog), or cloud-specific auto-join settings.

Key Options in a Service Configuration File

Service definitions register application endpoints with Consul for discovery and health checking. Below is an overview of essential fields:
You can define multiple health checks per service. Use deregister_critical_service_after to automatically remove unhealthy instances.
The image is a guide on interpreting a Consul agent configuration, highlighting key options in a service configuration file such as name, id, port, and check. It also notes that environment variables cannot configure the Consul client.
Next, we’ll walkthrough a real-world example, explaining each setting in depth and demonstrating best practices for high-availability and secure cluster management.

Watch Video