Before we begin be sure to download and install confd.
confd supports the following backends:
| Backend | Description | Watch Support | Documentation |
|---|---|---|---|
| env | Environment variables | No | Details |
| file | Local YAML/JSON files | Yes | Details |
| etcd | etcd v3 key-value store | Yes | Details |
| consul | HashiCorp Consul KV | Yes | Details |
| vault | HashiCorp Vault secrets | No | Details |
| redis | Redis key-value store | Yes | Details |
| zookeeper | Apache ZooKeeper | Yes | Details |
| dynamodb | AWS DynamoDB | No | Details |
| ssm | AWS Systems Manager Parameter Store | No | Details |
| secretsmanager | AWS Secrets Manager | No | Details |
| acm | AWS Certificate Manager | No | Details |
| imds | AWS EC2 Instance Metadata Service | No | Details |
This quick start uses the env and file backends which require no external services. For production use cases, see the backend-specific documentation linked above.
The env backend is the simplest way to get started.
export MYAPP_DATABASE_URL=db.example.com
export MYAPP_DATABASE_USER=adminsudo mkdir -p /etc/confd/{conf.d,templates}/etc/confd/conf.d/myconfig.toml:
[template]
src = "myconfig.conf.tmpl"
dest = "/tmp/myconfig.conf"
keys = [
"/myapp/database",
]/etc/confd/templates/myconfig.conf.tmpl:
[myconfig]
database_url = {{getv "/myapp/database/url"}}
database_user = {{getv "/myapp/database/user"}}
confd env --onetimeCheck the output:
cat /tmp/myconfig.confThe file backend reads configuration from local YAML or JSON files.
myapp.yaml:
myapp:
database:
url: db.example.com
user: adminsudo mkdir -p /etc/confd/{conf.d,templates}/etc/confd/conf.d/myconfig.toml:
[template]
src = "myconfig.conf.tmpl"
dest = "/tmp/myconfig.conf"
keys = [
"/myapp/database",
]/etc/confd/templates/myconfig.conf.tmpl:
[myconfig]
database_url = {{getv "/myapp/database/url"}}
database_user = {{getv "/myapp/database/user"}}
confd file --file myapp.yaml --onetimeconfd supports two modes of operation:
Process templates once and exit:
confd env --onetimePoll the backend at regular intervals:
confd env --interval 60Watch for changes in real-time (etcd, consul, redis, zookeeper, file):
confd file --file myapp.yaml --watch- Template Functions: See templates.md for available template functions
- Configuration: See configuration-guide.md for all configuration options
- Multi-Backend: See multi-backend.md for using multiple backends (e.g., Consul + Vault)
- Backend Details: Click the backend links above for authentication, advanced options, and examples
This example manages nginx config files using etcd or consul.
etcdctl put /myapp/subdomain myapp
etcdctl put /myapp/upstream/app1 "10.0.1.100:80"
etcdctl put /myapp/upstream/app2 "10.0.1.101:80"consul kv put myapp/subdomain myapp
consul kv put myapp/upstream/app1 "10.0.1.100:80"
consul kv put myapp/upstream/app2 "10.0.1.101:80"/etc/confd/conf.d/myapp-nginx.toml:
[template]
prefix = "/myapp"
src = "nginx.tmpl"
dest = "/tmp/myapp.conf"
owner = "nginx"
mode = "0644"
keys = [
"/subdomain",
"/upstream",
]
check_cmd = "/usr/sbin/nginx -t -c {{.src}}"
reload_cmd = "/usr/sbin/service nginx reload"/etc/confd/templates/nginx.tmpl:
upstream {{getv "/subdomain"}} {
{{range getvs "/upstream/*"}}
server {{.}};
{{end}}
}
server {
server_name {{getv "/subdomain"}}.example.com;
location / {
proxy_pass http://{{getv "/subdomain"}};
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# etcd
confd etcd --node http://127.0.0.1:2379 --watch
# consul
confd consul --node 127.0.0.1:8500 --watch