Manage API configuration and service discovery with HashiCorp Consul: KV store, watches, and env-consul templates.
Agentic Workflow: Read -> Reason -> Act (consul-config)
You are Consul Config (api/general) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — api context for consul-config
- Domain: Manage API configuration and service discovery with HashiCorp Consul: KV store, watches, and env-consul templates.
- kv-store: Read, write, list, and delete configuration keys in Consul KV —
consul kv put config/api/port 8080 - consul-template: Render config files from Consul KV with consul-template —
consul-template -template "config.ctmpl:config.json" -once - Check
knowledgeandprerequisites: consul, consul-template
2. Reason — think for consul-config
- For
kv-store: Read, write, list, and delete configuration keys in Consul KV — decide which checks to run - For
consul-template: Render config files from Consul KV with consul-template — decide which checks to run - Evaluate trust/policy:
kdesk trust+kdesk doctorpatterns for your inputs
3. Act — execute with consul-config tools
- Tools:
Glob,Grep,Read,Consul,Consul-template(see frontmattertools/allowed-tools) - Use
safe_pathfor any write; record evidence (paths, checksums) - Fingerprint:
consul-config:7db7d844
Consul Config
Manage API configuration centrally with Consul KV and templates.
When to Use
- Central config that changes without redeploys
- Feature flags and per-datacenter overrides
- Service discovery combined with config
Start Consul
consul agent -dev
KV Operations
consul kv put config/api/port 8080
consul kv get config/api/port
consul kv list config/
consul kv get -recurse config/api
consul kv delete config/api/port
Template
{"port": {{ key "config/api/port" }}, "retries": {{ keyOrDefault "config/api/feature-flags/retries" "3" }}}
consul-template -template "config.ctmpl:config.json" -once
consul-template -template "config.ctmpl:config.json:reload.sh"
Watches
consul watch -type keyprefix -prefix config/api env
Service Discovery
consul members
consul catalog services
curl http://localhost:8500/v1/kv/config/api/port
Testing
consul kv put config/api/port 9090
# consul-template re-renders and optionally reloads the app
consul-template -template "config.ctmpl:config.json:reload.sh"
Best Practices
- Use keyOrDefault in templates for resilient config
- Namespace keys by service: config//
- Version config with K/V indexes and CAS
- Use watches or consul-template for hot reloads
- Back up KV with consul kv export
- Never store secrets in KV; use Vault
- Add ACLs in production clusters
Capabilities
kv-store
Read, write, list, and delete configuration keys in Consul KV
Parameters:
key(string): KV key path such as config/api/portvalue(string): Value to store
Commands:
consul kv put config/api/port 8080consul kv get config/api/portconsul kv list config/consul kv delete config/api/port
Examples:
- consul kv put config/api/feature-flags/retries 3
- consul kv get -recurse config/api
- consul kv put -flags=0 config/api/deploy "blue"
consul-template
Render config files from Consul KV with consul-template
Parameters:
template_file(string): Go template path mapping such as config.ctmpl:config.json
Commands:
consul-template -template "config.ctmpl:config.json" -onceconsul-template -template "config.ctmpl:config.json:reload.sh"consul watch -type keyprefix -prefix config/api envconsul members
Examples:
- consul-template -template "config.ctmpl:config.json" -once
- consul watch -type keyprefix -prefix config/api env
- consul members -detailed