A Story of KV Store & ContainersStore your Traefik configuration in etcd and let Traefik automatically watch for changes. The etcd provider enables centralized configuration management with distributed consistency and high availability.
✅ Centralized configuration - Single source of truth for all Traefik instances
✅ High availability - Distributed key-value store with strong consistency
✅ Real-time updates - Traefik watches for changes and updates instantly
✅ Multi-instance support - Share configuration across multiple Traefik replicas
✅ Version control - Track configuration changes over time
# Create a routeretcdctl put /traefik/http/routers/my-router/rule "Host(`example.com`)"etcdctl put /traefik/http/routers/my-router/service "my-service"etcdctl put /traefik/http/routers/my-router/entrypoints/0 "web"# Create a serviceetcdctl put /traefik/http/services/my-service/loadbalancer/servers/0/url "http://192.168.1.10:8080"etcdctl put /traefik/http/services/my-service/loadbalancer/servers/1/url "http://192.168.1.11:8080"
3
Configuration Auto-Loads
Traefik automatically detects changes and updates routing!
# Router configurationetcdctl put /traefik/http/routers/web/rule "Host(`www.example.com`)"etcdctl put /traefik/http/routers/web/service "web-service"etcdctl put /traefik/http/routers/web/entrypoints/0 "websecure"etcdctl put /traefik/http/routers/web/tls/certResolver "letsencrypt"# Service configurationetcdctl put /traefik/http/services/web-service/loadbalancer/servers/0/url "http://10.0.1.10:80"etcdctl put /traefik/http/services/web-service/loadbalancer/servers/1/url "http://10.0.1.11:80"etcdctl put /traefik/http/services/web-service/loadbalancer/healthcheck/path "/health"etcdctl put /traefik/http/services/web-service/loadbalancer/healthcheck/interval "10s"
# Basic Auth middlewareetcdctl put /traefik/http/middlewares/auth/basicauth/users/0 "admin:$$apr1$$H6uskkkW$$IgXLP6ewTrSuBkTrqE8wj/"# Rate limitingetcdctl put /traefik/http/middlewares/ratelimit/ratelimit/average "100"etcdctl put /traefik/http/middlewares/ratelimit/ratelimit/burst "50"# Compressionetcdctl put /traefik/http/middlewares/compress/compress ""# Headersetcdctl put /traefik/http/middlewares/security/headers/sslredirect "true"etcdctl put /traefik/http/middlewares/security/headers/stsseconds "31536000"
Attach to router:
etcdctl put /traefik/http/routers/api/middlewares/0 "auth"etcdctl put /traefik/http/routers/api/middlewares/1 "ratelimit"
# TCP Routeretcdctl put /traefik/tcp/routers/postgres/rule "HostSNI(`db.example.com`)"etcdctl put /traefik/tcp/routers/postgres/service "postgres-service"etcdctl put /traefik/tcp/routers/postgres/entrypoints/0 "postgresql"etcdctl put /traefik/tcp/routers/postgres/tls/passthrough "true"# TCP Serviceetcdctl put /traefik/tcp/services/postgres-service/loadbalancer/servers/0/address "10.0.1.50:5432"
# TLS Optionsetcdctl put /traefik/tls/options/modern/minversion "VersionTLS13"etcdctl put /traefik/tls/options/modern/ciphersuites/0 "TLS_AES_128_GCM_SHA256"etcdctl put /traefik/tls/options/modern/ciphersuites/1 "TLS_AES_256_GCM_SHA384"# TLS Store (default certificate)etcdctl put /traefik/tls/stores/default/defaultcertificate/certfile "/certs/default.crt"etcdctl put /traefik/tls/stores/default/defaultcertificate/keyfile "/certs/default.key"
#!/bin/bash# Create API routeretcdctl put /traefik/http/routers/api/rule "Host(\`api.example.com\`) && PathPrefix(\`/v1\`)"etcdctl put /traefik/http/routers/api/service "api-service"etcdctl put /traefik/http/routers/api/entrypoints/0 "websecure"etcdctl put /traefik/http/routers/api/middlewares/0 "api-auth"etcdctl put /traefik/http/routers/api/middlewares/1 "api-ratelimit"etcdctl put /traefik/http/routers/api/tls/certresolver "letsencrypt"# Create API service with load balancingetcdctl put /traefik/http/services/api-service/loadbalancer/servers/0/url "http://10.0.1.20:8080"etcdctl put /traefik/http/services/api-service/loadbalancer/servers/1/url "http://10.0.1.21:8080"etcdctl put /traefik/http/services/api-service/loadbalancer/servers/2/url "http://10.0.1.22:8080"etcdctl put /traefik/http/services/api-service/loadbalancer/healthcheck/path "/health"etcdctl put /traefik/http/services/api-service/loadbalancer/healthcheck/interval "10s"etcdctl put /traefik/http/services/api-service/loadbalancer/sticky/cookie/name "api_session"etcdctl put /traefik/http/services/api-service/loadbalancer/sticky/cookie/httponly "true"# Create middlewareetcdctl put /traefik/http/middlewares/api-auth/basicauth/users/0 "api:$$apr1$$..."etcdctl put /traefik/http/middlewares/api-ratelimit/ratelimit/average "100"etcdctl put /traefik/http/middlewares/api-ratelimit/ratelimit/period "1s"etcdctl put /traefik/http/middlewares/api-ratelimit/ratelimit/burst "200"echo "API configuration loaded into etcd"
#!/bin/bash# backup-traefik-config.shBACKUP_FILE="traefik-config-$(date +%Y%m%d-%H%M%S).json"# Export all Traefik configurationetcdctl get /traefik --prefix --print-value-only > "$BACKUP_FILE"echo "Configuration backed up to $BACKUP_FILE"
#!/bin/bash# restore-traefik-config.shBACKUP_FILE="$1"if [ -z "$BACKUP_FILE" ]; then echo "Usage: $0 <backup-file>" exit 1fi# Delete existing configurationetcdctl del /traefik --prefix# Restore from backupcat "$BACKUP_FILE" | while IFS= read -r line; do # Parse and restore each key-value pair # (simplified - adapt based on backup format)doneecho "Configuration restored from $BACKUP_FILE"