Overview
Traefik v3 serves as the edge router and API gateway for the microservices-app. It provides:- HTTP/2 and gRPC routing
- Service discovery (Docker labels and Kubernetes CRDs)
- Middleware (CORS, rate limiting, retries, authentication)
- OpenTelemetry tracing integration
Architecture
Traefik sits at the edge and routes traffic to backend services:Docker Compose Configuration
For local development with Docker Compose, Traefik uses labels for service discovery.Traefik Service
Fromdocker-compose.yml:
Static Configuration
Fromdeploy/traefik/traefik.yml:
exposedByDefault: false: Only services withtraefik.enable=trueare exposednetwork: Ensures Traefik uses the correct Docker networkfileprovider: Loads middleware fromdeploy/traefik/dynamic/
Routing Rules
Services declare routing rules via Docker labels.gRPC Service (Greeter)
- Rule: Matches gRPC service path
/greeter.v1.GreeterService/* - Priority: 100 (higher priority than frontend catch-all)
- Middlewares: CORS, auth, rate limiting, retry (defined in
middleware.yml) - Scheme:
h2c(HTTP/2 Cleartext for gRPC)
Gateway Service
Auth Service
auth middleware (to avoid circular dependency).
Frontend
Middleware
Middleware is defined indeploy/traefik/dynamic/middleware.yml.
CORS Middleware
Allows cross-origin requests from the frontend:Connect-Protocol-Version: connect-rpc protocol versionGrpc-*: gRPC-Web headersIdempotency-Key: For idempotent requests
Auth Middleware
Forwards authentication to the auth service:- Traefik intercepts request
- Forwards
Authorizationheader tohttp://auth-service:8090/verify - If auth service returns 200, request proceeds with
X-User-Idheader added - If auth service returns 401/403, request is rejected
Rate Limit Middleware
Limits requests per second:- average: 100 requests/second sustained
- burst: Allow bursts up to 50 requests
Retry Middleware
Retries failed requests:Kubernetes Configuration
For Kubernetes deployment, Traefik uses CRDs (IngressRoute, Middleware) defined in Nixidy.Helm Chart
Fromdeploy/nixidy/env/traefik.nix:
Middleware CRD
Example CORS middleware:IngressRoute CRD
Example greeter route:Accessing Traefik
- Docker Compose: http://localhost:30081
- Kubernetes: http://localhost:30081 (NodePort)
Dashboard
Traefik dashboard is not enabled by default. To enable in development:Debugging
Check Traefik Logs
Docker Compose:List Routes
Docker Compose:Test Endpoints
Next Steps
- Deploy with Kubernetes: Kubernetes Deployment
- Configure observability: Observability Stack
- Add middleware: See Traefik Middleware docs