Part 4 · 1 chapters · ~8 min

Consul and etcd as Configuration Stores

Consul's KV store, service catalogue and watches, consul-template and envconsul, etcd as Kubernetes' brain and as an application config store, watches and leases, and when a dedicated config store is better than files and flags.

8

Consul KV, etcd and watches

code
# Consul: store config, watch it, render it
consul kv put config/ledger/transfer_limit_kobo 20000000
consul watch -type=key -key=config/ledger/transfer_limit_kobo ./reload.sh
consul-template -template "app.tmpl:app.conf:systemctl reload ledger"     # re-render and reload on change

# etcd: the same idea with revisions and leases
etcdctl put /config/ledger/limit 20000000
etcdctl watch /config/ledger/ --prefix
etcdctl lease grant 30 && etcdctl put --lease=<id> /locks/reconcile owner-a   # expires unless kept alive
storeconsistencytypical use
ConsulRaft (strongly consistent writes), gossip for membershipservice discovery plus KV config, with consul-template
etcdRaft, linearisable reads by defaultKubernetes state; leader election and small config for platforms
ZooKeeperZab consensusolder Kafka, Hadoop-era systems

These stores are for small, critical, frequently read configuration: values in the kilobytes, not documents. Do not put application data in them, and never point an application at the Kubernetes etcd.