consul
Configure Consul service discovery, health checks, key-value settings, and service-mesh intentions.
SKILL.mdskills/consul/SKILL.md
GitHubHashiCorp Consul AI Skill Guide (Claude)
Overview & Engine Architecture
Consul provides service discovery, health checking, a hierarchical KV store, and optional Connect service mesh (mTLS + intentions). Servers form a Raft quorum; client agents on nodes register services and answer DNS (*.service.consul) / HTTP catalog queries. In any shared environment treat ACLs as mandatory—bootstrap once, store the management token offline, issue least-privilege tokens to agents and sidecars. Put secrets in @vault, not Consul KV.
┌─────────────────────────────────────────────────────────────┐
│ Consul control plane │
│ │
│ Servers (3 or 5) ──Raft──► leader + replicated state │
│ ▲ gossip (LAN) / RPC │
│ Client agents on nodes │
│ ├── service + check registration │
│ ├── DNS :8600 / HTTP API catalog │
│ └── Connect: Envoy sidecars + intentions │
│ │
│ Multi-DC: WAN federation (8300/8302) + ACL replication │
└─────────────────────────────────────────────────────────────┘
When to use / when not to
Use when
- Registering services with HTTP/TCP/gRPC checks so load balancers and apps resolve healthy instances only.
- Central non-secret config in KV; prepared queries / resolvers for failover.
- Service mesh intentions (allow/deny) with Connect proxies—often beside
@nomad.
Do not use when
- You need Kubernetes-native Service/Endpoints only and already run full K8s discovery →
@kubernetes. - The data is passwords, API keys, or certs →
@vault(Consul KV is for config, not secret source of truth). - Someone asks for a single Consul server “for prod simplicity” → refuse; require 3 or 5 voters.
Operational Capabilities & Agent Directives
- Odd server quorum (3 or 5) in production; separate clients from servers.
- Enable ACLs; bootstrap once; never paste the bootstrap SecretID into Git or chat—create scoped tokens immediately.
- Honest health checks with sensible
interval/timeout; usederegister_critical_service_afterfor crash-loop cleanup. - KV for config only; integrate
@vaultfor credentials and dynamic secrets. - Intentions default-deny in mesh environments; explicitly allow
web→api(etc.). - Multi-DC: set
primary_datacenter, enable ACL token replication on secondaries; verify/v1/acl/replication. - Tag services with env/version for canary routing; document gossip encryption key rotation separately from ACLs.
- Never invent Gossip keys, ACL tokens, or TLS material—reference existing files/Secret backends.
Production Example: register, discover, intention, ops checks
api.service.hcl (agent config snippet style / register JSON equivalent):
{
"service": {
"name": "api",
"id": "api-1",
"port": 8080,
"tags": ["prod", "v1"],
"meta": {
"version": "1.4.2"
},
"check": {
"id": "api-http",
"name": "HTTP API health",
"http": "http://127.0.0.1:8080/healthz",
"interval": "10s",
"timeout": "2s",
"deregister_critical_service_after": "30m",
"failures_before_critical": 3
}
}
}
# Registration & discovery
consul services register api.json
consul catalog services
consul health service api -passing
dig @127.0.0.1 -p 8600 api.service.consul
# KV (non-secret config)
consul kv put apps/api/log_level info
consul kv get apps/api/log_level
consul kv export apps/api/ > api-kv-backup.json
# Connect intention (mesh)
consul intention create -allow web api
consul intention list
# Operator health
consul members
consul operator raft list-peers
consul info
ACL bootstrap (run once; store offline—do not commit):
consul acl bootstrap
# Immediately create agent/service tokens with least privilege; revoke/replace if exposed
Technical Troubleshooting Matrix
| Signature | Likely cause | Fix path |
|---|---|---|
| Empty DNS / no instances | Checks critical or not registered | consul health service NAME; fix check URL/port |
| Split views across clients | ACL denial or stale agent | Token policy; consul members; agent logs |
| Leader election churn | Network partition / disk IOPS | raft list-peers; stabilize disk & latency |
| KV / catalog denied | Missing ACL policy | Grant least-privilege service/key rules |
| Mesh connect timeout | Missing intention or sidecar token | intention list; ensure proxy has service token |
| Secondary DC auth fails | ACL replication broken | Check primary_datacenter, replication token, /v1/acl/replication |
| WAN join fails | 8300/8302 blocked | Open RPC/WAN gossip per federation model |
| Crash-loop still in DNS | No deregister-after | Set deregister_critical_service_after |
Best Practices
- Bootstrap ACLs before exposing UI/API beyond localhost.
- Backup Raft/KV on a schedule; test restore in staging.
- Prefer prepared queries / service resolvers for multi-DC failover designs.
- Pair with
@nomadservice blocks for registration from jobspecs;@traefikcan use Consul catalog as a provider. - Monitor Raft peer health and check critical counts as SLO signals.
- Document token lifecycle (agent, service, replication, management offline).
Limitations
- Consul health checks are not full APM—pair with metrics/tracing (
@opentelemetry). - Connect sidecars add CPU/latency and operational cost.
- Multi-DC WAN federation and ACL replication need careful network and identity planning.
- Stop and ask if datacenter topology, ACL state, or whether KV vs Vault is intended.
Related Skills
@nomad— scheduler that registers services into Consul@vault— secrets companion (not Consul KV)@traefik— edge proxy with Consul provider@terraform— provision Consul server/client fleet@docker— local Consul agent/dev containers for labs only
Agent Operational Directive
MANDATORY: Use 3/5 server voters in prod; enable ACLs and least-privilege tokens. Keep passwords out of KV (
@vault). Make health checks reflect real readiness; set deregister-after for critical churn. Never invent or commit bootstrap/gossip/ACL secrets.