Consul Ops Pro cheat sheet
Consul Ops Pro · Keep the key ideas within reach.
Consul Architecture and Deployment Topologies
Consul agents run in either server or client mode; servers form the Raft quorum and maintain cluster state, while clients forward RPCs to servers and run local health checks.
A datacenter is the basic unit of Consul deployment; each datacenter has its own independent Raft group and gossip pool, and cross-datacenter communication occurs through the WAN gossip pool and RPC forwarding.
The gossip protocol (LAN and WAN) uses Serf and is responsible for membership, failure detection, and event broadcast; it is separate from Raft consensus used for state replication.
Raft requires a quorum of (N/2)+1 servers; a 3-server cluster tolerates 1 failure, a 5-server cluster tolerates 2 failures, and larger clusters increase write latency without proportional benefit.
Client agents are stateless except for local health check state; they can be scaled horizontally and are typically deployed on every node that hosts services.
Consul supports multiple datacenters with a single ACL and intention configuration when using enterprise features like replication; in open source, each datacenter must be configured separately.
Network segmentation: servers should be placed in a dedicated fault domain, and ports 8300 (RPC), 8301 (LAN gossip), 8302 (WAN gossip), 8500 (HTTP), and 8501 (HTTPS) must be allowed between appropriate components.
For production, deploy at least 3 servers (5 recommended for large clusters) across availability zones, and use client agents on all service nodes; avoid running servers on the same physical host as critical clients.
Consul on Kubernetes uses a Helm chart that deploys servers as a StatefulSet and clients as a DaemonSet; the connect-injector handles sidecar injection for service mesh.
Cluster Bootstrapping, Server Management, and Upgrades
Bootstrap a new cluster with
consul operator raft bootstrapor by starting the first server with-bootstrap-expect 3; the latter waits until the expected number of servers join before electing a leader.Use
consul operator raft list-peersto view the current Raft configuration andconsul operator raft remove-peerto remove a failed server that is not gracefully leaving.To add a server, start it with the same gossip encryption key and
-retry-joinpointing to an existing server; then useconsul operator raft add-peeror rely on automatic joining if-bootstrap-expectis not set.Graceful server removal: use
consul leaveon the server being removed; it will transfer leadership if it is the leader and then shut down.Upgrades should be performed one server at a time, waiting for the cluster to become healthy (
consul membersshows all alive andconsul operator raft list-peersshows a stable leader) before proceeding to the next server.Consul supports rolling upgrades across minor versions; always upgrade servers before clients, and ensure the new version's protocol is compatible (check the upgrade guides for version-specific notes).
Snapshot save and restore:
consul snapshot save backup.snapandconsul snapshot restore backup.snap; snapshots include KV, ACLs, intentions, and service catalog but not the Raft configuration.Autopilot (enabled by default) performs health checks on servers, stabilizes the Raft cluster after disruptions, and can automatically remove failed servers when
cleanup_dead_serversis true.To change the cluster's encryption key, use
consul keyringcommands: install new key on all servers and clients, then remove the old key; gossip encryption keys must be identical across all agents in a datacenter.
Service Registration, Health Checks, and Service Mesh (Connect)
Services can be registered via configuration files, the HTTP API (
/v1/agent/service/register), or by usingconsul services register; registrations are persisted in the catalog and survive agent restarts if defined in config files.Health checks can be script, HTTP, TCP, TTL, Docker, or gRPC; a service is considered healthy only if all its checks pass, and the DNS interface returns only passing instances by default.
TTL checks require periodic updates via
consul services checkor the/v1/agent/check/updateendpoint; if the TTL expires, the check becomes critical.Connect enables service mesh with sidecar proxies; enable it with
connect { enabled = true }in the agent config, and register a service with a sidecar proxy usingconnect { sidecar_service {} }.Intentions define allowed connections between services; they are deny by default when ACLs are enabled, and can be managed via API, CLI (
consul intention), or configuration entries.Service defaults and service intentions can be configured centrally using configuration entries (e.g.,
service-defaults,service-intentions) for consistent mesh behavior.Health check definitions support
interval,timeout,deregister_critical_service_after, andstatus; the latter can set an initial status to avoid false alarms during startup.For service mesh, sidecar proxies can be deployed manually or automatically via
consul connect envoycommand; Envoy is the default proxy, and its configuration is generated by Consul.Service tags and meta can be used for filtering and routing; they are included in DNS SRV records and API responses, and can be used in intentions for finer-grained control.
KV Store, Intentions, and Access Control Lists (ACLs)
The KV store is a hierarchical key/value store accessible via HTTP API (
/v1/kv/), CLI (consul kv), and DNS with TXT records; keys are case-sensitive and support atomic operations via CAS (Check-And-Set).KV entries have associated flags, create/modify indices, and optional session binding for locking; sessions enable distributed locks with TTL and health checks.
ACLs are enabled by setting
acl { enabled = true }on all servers; the bootstrap token is generated withconsul acl bootstrapand has unrestricted privileges.ACL policies are composed of rules that grant read, write, or deny on resources like
service,node,key,query,intention, andoperator; policies are attached to tokens.Token types: management tokens (global access), client tokens (limited by policies), and anonymous tokens (used when no token provided); the anonymous token policy should be minimal.
Intentions are defined with source and destination service names and an action (allow/deny); they are evaluated in order of precedence: exact match > prefix match > wildcard, and deny overrides allow.
ACL replication in enterprise: primary datacenter replicates ACL policies, tokens, and intentions to secondary datacenters; in open source, each datacenter must be configured independently.
Use
consul acl token createwith-policy-nameor-policy-idto create tokens; tokens can also be set via theCONSUL_HTTP_TOKENenvironment variable or-tokenflag.KV locks: create a session with
consul session create, then acquire a lock withconsul kv put -acquire=<session> key value; release with-releaseor when session expires.
Security: TLS, Gossip Encryption, and Secrets Management
Gossip encryption uses a symmetric key (32 bytes base64-encoded) configured via
encryptin the agent config or-encryptflag; all agents in a datacenter must use the same key.TLS for RPC and HTTP: configure
verify_incoming,verify_outgoing, andverify_server_hostnameon servers; clients needverify_outgoingand CA certificate to verify servers.Certificates must include
server.<datacenter>.<domain>in the SAN for server verification; useconsul tls cert createto generate certificates with proper SANs.Enable HTTPS for the HTTP API by setting
ports { https = 8501 }and providingcert_fileandkey_file; the HTTP port can be disabled or redirected.ACL tokens should be used to protect the KV store and service registration; use
acl { tokens { default = "..." } }to set a default token for an agent.Secrets management: Consul can store secrets in the KV store, but for production, integrate with Vault using the Consul secrets engine or use Vault to manage Consul ACL tokens.
The
consul tls ca createcommand creates a CA andconsul tls cert create -servercreates a server certificate; distribute the CA certificate to all agents.To rotate gossip keys, use
consul keyring -install <new-key>on all agents, thenconsul keyring -use <new-key>, and finallyconsul keyring -remove <old-key>.TLS can be used for the Connect service mesh with
connect { ca_provider = "consul" }or Vault; the built-in CA is not recommended for production multi-datacenter.
Observability, Monitoring, and Logging
Consul exposes metrics in Prometheus format at
/v1/agent/metricsand via telemetry configuration; key metrics includeconsul.runtime.alloc_bytes,consul.raft.apply,consul.serf.member.flap, andconsul.http.*.Enable telemetry with
telemetry { prometheus_retention_time = "1m" }and optionallydogstatsd_addrfor StatsD; metrics can be scraped by Prometheus.Logs are written to stderr by default; set
log_fileandlog_levelin the agent config; levels are TRACE, DEBUG, INFO, WARN, ERR.Health checks generate events and can trigger alerts; use
consul watchto monitor changes and integrate with monitoring systems.The
/v1/status/leaderand/v1/status/peersendpoints provide cluster health information;consul operator raft list-peersshows Raft configuration.Distributed tracing for Connect can be enabled with
connect { enable_central_service_config = true }and configuring Envoy tracing; Consul supports Jaeger and Zipkin.Audit logging (enterprise) logs all API requests with tokens and can be configured to write to a file or syslog.
Use
consul monitorto stream logs from a running agent at a specified log level; useful for debugging without restarting.Key alerts:
consul.raft.leader.lastContact> 200ms indicates leader contention;consul.serf.queue.Intent> 0 indicates gossip issues.
Troubleshooting, Failure Recovery, and Backup/Restore
If a server loses quorum, it cannot process writes; recover by restoring a snapshot or by using
consul operator raft recoverto force a new cluster from a peer's data.To recover from a lost quorum, identify a server with the most up-to-date data, stop all servers, and restart that server with
-bootstrap-expect 1and-bootstrapto form a new cluster, then rejoin others.Snapshot restore must be performed on a stopped server or on a new cluster; use
consul snapshot restorewith the-http-addrof a running server.Common issues: port conflicts (check
consul membersand firewall), TLS misconfiguration (check certificate SANs andverify_outgoing), and ACL token missing (checkconsul acl token list).Use
consul debugto collect a debug bundle including logs, metrics, and configuration for support.If a client agent cannot connect to servers, verify
retry_joinand network connectivity;consul infoshows agent status andconsul membersshows cluster membership.For a failed server, remove it from Raft with
consul operator raft remove-peer -id <node-id>; then start a new server with the same configuration.Backup strategy: take regular snapshots (e.g., every 24 hours) and store them off-cluster; test restore procedures periodically.
DNS issues: ensure
recursorsare configured if using Consul for external DNS; checkconsul catalog nodesto verify service discovery.
Automation, Infrastructure as Code, and Enterprise Features
Consul integrates with Terraform via the Consul provider to manage services, KV, ACLs, and intentions as code; use
terraform planandapplyfor changes.The Consul Helm chart supports declarative configuration of servers, clients, and Connect injector; values.yaml can be version-controlled.
Nomad integration: Consul is used for service discovery and Connect; Nomad job specifications can register services and health checks automatically.
Enterprise features include: automated backups, redundancy zones, read replicas, audit logging, namespaces, and SSO/OIDC authentication.
Namespaces (enterprise) allow multiple teams to share a cluster with isolated service and KV namespaces; ACLs can be scoped to namespaces.
Admin partitions (enterprise) provide larger-scale isolation, allowing multiple datacenters to be managed as a single unit with separate Raft groups.
Consul's API can be automated with CI/CD pipelines; use
consul services registerin deployment scripts or the HTTP API.Vault integration: use Vault to manage Consul ACL tokens and certificates; the Consul secrets engine dynamically generates tokens.
Consul on Kubernetes can be automated with the official Helm chart and the Consul K8s CLI; use
consul-k8s installfor a quick setup.