Docker ile Deployment
Consul Guardian, tek bir Docker image olarak dağıtılır. Watch, dashboard ve diğer tüm komutları aynı image üzerinden çalıştırabilirsin.
Hızlı Başlangıç
docker run -d \
--name consul-guardian \
-e CONSUL_GUARDIAN_CONSUL_ADDRESS=http://consul:8500 \
-e CONSUL_GUARDIAN_CONSUL_TOKEN=your-token \
-v /data/consul-backup:/home/guardian/repo \
-p 9090:9090 \
ghcr.io/consul-guardian/consul-guardian:latest \
dashboard --prefix "config/" --listen :9090
docker-compose Örneği
Consul ve Guardian'ı birlikte çalıştırmak için:
# docker-compose.yaml
version: "3.8"
services:
consul:
image: hashicorp/consul:1.18
command: agent -server -bootstrap-expect=1 -client=0.0.0.0 -ui
ports:
- "8500:8500"
volumes:
- consul-data:/consul/data
guardian:
image: ghcr.io/consul-guardian/consul-guardian:latest
command: >
dashboard
--prefix "config/,env/,feature-flags/"
--listen :9090
ports:
- "9090:9090"
environment:
CONSUL_GUARDIAN_CONSUL_ADDRESS: "http://consul:8500"
CONSUL_GUARDIAN_CONSUL_TOKEN: "${CONSUL_TOKEN}"
CONSUL_GUARDIAN_GIT_AUTO_PUSH: "false"
CONSUL_GUARDIAN_SNAPSHOT_ENABLED: "true"
CONSUL_GUARDIAN_SNAPSHOT_SCHEDULE: "0 */6 * * *"
volumes:
- backup-repo:/home/guardian/repo
- snapshot-storage:/home/guardian/snapshots
depends_on:
- consul
restart: unless-stopped
volumes:
consul-data:
backup-repo:
snapshot-storage:
Çalıştırmak için:
# Consul token'ını .env dosyasına yaz
echo "CONSUL_TOKEN=your-token-here" > .env
# Başlat
docker compose up -d
# Log'ları takip et
docker compose logs -f guardian
Ortam Değişkenleri
Tüm yapılandırma değerleri CONSUL_GUARDIAN_ öneki ile ortam değişkeni olarak geçirilebilir. YAML'deki iç içe yapılar _ ile ayrılır:
| Ortam Değişkeni | YAML Karşılığı | Açıklama |
|---|---|---|
CONSUL_GUARDIAN_CONSUL_ADDRESS | consul.address | Consul sunucu adresi |
CONSUL_GUARDIAN_CONSUL_TOKEN | consul.token | ACL token |
CONSUL_GUARDIAN_CONSUL_DATACENTER | consul.datacenter | Datacenter adı |
CONSUL_GUARDIAN_GIT_REPO_PATH | git.repo_path | Git repo dizini |
CONSUL_GUARDIAN_GIT_AUTO_PUSH | git.auto_push | Otomatik push |
CONSUL_GUARDIAN_SNAPSHOT_ENABLED | snapshot.enabled | Snapshot aktif mi |
CONSUL_GUARDIAN_SNAPSHOT_SCHEDULE | snapshot.schedule | Cron ifadesi |
CONSUL_GUARDIAN_LOG_LEVEL | logging.level | Log seviyesi |
Volume'lar
Guardian iki temel volume kullanır:
Git Repo (/home/guardian/repo)
KV değişikliklerinin commit edildiği Git repo'su. Bu volume'u kalıcı (persistent) yapmalısın, yoksa container restart'ında geçmiş kaybolur.
Snapshot Depolama (/home/guardian/snapshots)
Yerel depolama kullanıyorsan snapshot dosyalarının saklandığı dizin. S3/GCS kullanıyorsan bu volume'a gerek yok.
Network Ayarları
Guardian'ın Consul'a erişebilmesi gerekir. Docker network konfigürasyonuna dikkat et:
# Aynı Docker network'ünde
docker network create consul-net
docker run --network consul-net --name consul ...
docker run --network consul-net --name guardian ...
# Host network'ünden Consul'a erişim (macOS/Windows)
-e CONSUL_GUARDIAN_CONSUL_ADDRESS=http://host.docker.internal:8500
Sağlık Kontrolü
Container sağlık kontrolü için:
healthcheck:
test: ["CMD", "consul-guardian", "status"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
Gerçek Senaryo: Production Docker Deployment
# docker-compose.prod.yaml
services:
guardian:
image: ghcr.io/consul-guardian/consul-guardian:latest
command: >
dashboard
--prefix "config/,env/"
--listen :9090
ports:
- "9090:9090"
environment:
CONSUL_GUARDIAN_CONSUL_ADDRESS: "http://consul.internal:8500"
CONSUL_GUARDIAN_CONSUL_TOKEN_FILE: "/run/secrets/consul_token"
CONSUL_GUARDIAN_GIT_AUTO_PUSH: "true"
CONSUL_GUARDIAN_GIT_REMOTE: "origin"
CONSUL_GUARDIAN_GIT_BRANCH: "main"
CONSUL_GUARDIAN_SNAPSHOT_ENABLED: "true"
CONSUL_GUARDIAN_SNAPSHOT_SCHEDULE: "0 */4 * * *"
CONSUL_GUARDIAN_SNAPSHOT_STORAGE_TYPE: "s3"
CONSUL_GUARDIAN_SNAPSHOT_STORAGE_BUCKET: "acme-consul-backups"
CONSUL_GUARDIAN_LOG_LEVEL: "info"
CONSUL_GUARDIAN_LOG_FORMAT: "json"
volumes:
- /data/consul-backup:/home/guardian/repo
secrets:
- consul_token
- git_ssh_key
deploy:
resources:
limits:
memory: 256M
cpus: "0.5"
restart: always
logging:
driver: json-file
options:
max-size: "50m"
max-file: "3"
secrets:
consul_token:
external: true
git_ssh_key:
external: true