Files
Rezepte/TRAEFIK_DEPLOYMENT.md
2025-09-22 16:35:59 +02:00

4.2 KiB

Traefik Proxy Deployment Guide

🚀 Was ist Traefik?

Traefik ist ein moderner HTTP-Reverse-Proxy und Load Balancer, der:

  • Automatische Service-Discovery aus Docker-Labels
  • Automatische SSL-Zertifikate via Let's Encrypt
  • Load Balancing zwischen mehreren Instanzen
  • Dashboard für Überwachung
  • Middleware für Auth, Rate Limiting, etc.

📁 Traefik Setup Dateien

1. docker-compose.traefik.yml

Vollständiger Stack mit Traefik, MySQL, Backend und Frontend

2. .env.traefik.example

Template für Umgebungsvariablen mit Domain-Konfiguration

3. deploy-traefik.sh

Automatisches Deployment-Skript

🌐 Domain-Konfiguration

DNS-Einträge erforderlich:

# A-Records auf die IP Ihres Servers:
rezepte.my.domain.com    → 1.2.3.4
traefik.my.domain.com    → 1.2.3.4

# Oder Wildcard (einfacher):
*.my.domain.com          → 1.2.3.4

.env.production Beispiel:

DOMAIN=my.domain.com
ACME_EMAIL=admin@my.domain.com
MYSQL_PASSWORD=super_secure_password_123
MYSQL_ROOT_PASSWORD=even_more_secure_root_password_456
BACKEND_IMAGE=ghcr.io/username/rezepte-klaus-backend:latest
FRONTEND_IMAGE=ghcr.io/username/rezepte-klaus-frontend:latest

🔧 Server-Deployment

Minimale Dateien auf Server:

# Server-Struktur
/opt/rezepte-klaus/
├── docker-compose.traefik.yml
├── .env.production
├── deploy-traefik.sh
├── Rezepte.sql
├── ingredients.sql
├── Zubereitung.sql
└── rezepte_bilder.sql

Deployment-Schritte:

# 1. Dateien auf Server kopieren
scp docker-compose.traefik.yml user@server:/opt/rezepte-klaus/
scp .env.production user@server:/opt/rezepte-klaus/
scp *.sql user@server:/opt/rezepte-klaus/
scp deploy-traefik.sh user@server:/opt/rezepte-klaus/

# 2. Auf Server einloggen und deployen
ssh user@server
cd /opt/rezepte-klaus
chmod +x deploy-traefik.sh
./deploy-traefik.sh

🔒 SSL/HTTPS Features

  • Automatische Let's Encrypt Zertifikate
  • Automatische HTTP → HTTPS Weiterleitung
  • HSTS Security Headers
  • Zertifikat-Erneuerung automatisch

🎯 Zugangspunkte

Nach erfolgreichem Deployment:

📱 Haupt-Anwendung:

https://rezepte.my.domain.com

🎛️ Traefik Dashboard:

https://traefik.my.domain.com
Username: admin
Password: admin (BITTE ÄNDERN!)

🔧 Traefik Dashboard Auth ändern

Neues Passwort generieren:

# Mit htpasswd (Apache utils)
htpasswd -nb admin new_password

# Mit Python
python3 -c "import crypt; print(crypt.crypt('new_password', crypt.mksalt(crypt.METHOD_SHA512)))"

# Mit Docker
docker run --rm httpd:alpine htpasswd -nbB admin new_password

Im docker-compose.traefik.yml ersetzen:

- "traefik.http.middlewares.auth.basicauth.users=admin:$$2y$$10$$NEW_HASH_HERE"

📊 Überwachung

Logs anzeigen:

# Alle Services
docker-compose -f docker-compose.traefik.yml logs -f

# Nur Traefik
docker-compose -f docker-compose.traefik.yml logs -f traefik

# Nur Backend
docker-compose -f docker-compose.traefik.yml logs -f backend

Service Status:

docker-compose -f docker-compose.traefik.yml ps

🛠️ Wartung

Updates deployen:

docker-compose -f docker-compose.traefik.yml pull
docker-compose -f docker-compose.traefik.yml up -d

Container neustarten:

docker-compose -f docker-compose.traefik.yml restart

Vollständiger Neustart:

docker-compose -f docker-compose.traefik.yml down
docker-compose -f docker-compose.traefik.yml up -d

🔍 Troubleshooting

SSL-Zertifikat Probleme:

  1. DNS-Einträge prüfen: nslookup rezepte.my.domain.com
  2. Firewall-Ports 80/443 öffnen
  3. Traefik Logs prüfen: docker logs traefik

Service nicht erreichbar:

  1. Container Status: docker-compose ps
  2. Health Checks: docker inspect container_name
  3. Netzwerk: docker network ls

Vorteile der Traefik-Lösung:

  • 🔒 Automatisches HTTPS mit Let's Encrypt
  • 🌐 Subdomain-basiertes Routing (rezepte.domain.com)
  • 📊 Web-Dashboard für Monitoring
  • 🔄 Automatische Service-Discovery
  • 🛡️ Integrierte Sicherheits-Middleware
  • 📈 Load Balancing für Skalierung
  • 🔧 Zero-Downtime Deployments

Das ist die professionelle Lösung für Produktions-Deployments! 🚀