Documentation Index
Fetch the complete documentation index at: https://mintlify.com/traefik/traefik/llms.txt
Use this file to discover all available pages before exploring further.
Services
Defining Backend Services and Load Balancing
Services define how to reach the actual backend servers that handle requests. They are part of the dynamic configuration.
HTTP Services
Load Balancer Service
The most common service type that distributes requests across multiple backend servers:
http:
services:
my-service:
loadBalancer:
servers:
- url: "http://192.168.1.10:8080"
- url: "http://192.168.1.11:8080"
- url: "http://192.168.1.12:8080"
[http.services.my-service.loadBalancer]
[[http.services.my-service.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[[http.services.my-service.loadBalancer.servers]]
url = "http://192.168.1.11:8080"
[[http.services.my-service.loadBalancer.servers]]
url = "http://192.168.1.12:8080"
Backend server URL (must include scheme: http:// or https://)
Load Balancing Strategies
Weighted Round Robin (WRR)
Default strategy that distributes requests based on server weights:
http:
services:
weighted-service:
loadBalancer:
strategy: "wrr"
servers:
- url: "http://192.168.1.10:8080"
weight: 3
- url: "http://192.168.1.11:8080"
weight: 1
[http.services.weighted-service.loadBalancer]
strategy = "wrr"
[[http.services.weighted-service.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
weight = 3
[[http.services.weighted-service.loadBalancer.servers]]
url = "http://192.168.1.11:8080"
weight = 1
With these weights, the first server receives 75% of traffic (3/4) and the second receives 25% (1/4).
Power of Two Choices (P2C)
Selects the least loaded server from two random choices:
http:
services:
dynamic-service:
loadBalancer:
strategy: "p2c"
servers:
- url: "http://192.168.1.10:8080"
- url: "http://192.168.1.11:8080"
- url: "http://192.168.1.12:8080"
[http.services.dynamic-service.loadBalancer]
strategy = "p2c"
[[http.services.dynamic-service.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[[http.services.dynamic-service.loadBalancer.servers]]
url = "http://192.168.1.11:8080"
[[http.services.dynamic-service.loadBalancer.servers]]
url = "http://192.168.1.12:8080"
Highest Random Weight (HRW)
Provides consistent hashing for sticky sessions:
http:
services:
consistent-service:
loadBalancer:
strategy: "hrw"
servers:
- url: "http://192.168.1.10:8080"
- url: "http://192.168.1.11:8080"
[http.services.consistent-service.loadBalancer]
strategy = "hrw"
[[http.services.consistent-service.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[[http.services.consistent-service.loadBalancer.servers]]
url = "http://192.168.1.11:8080"
Sticky Sessions
Maintain session affinity using cookies:
http:
services:
sticky-service:
loadBalancer:
sticky:
cookie:
name: "server_id"
secure: true
httpOnly: true
sameSite: "lax"
servers:
- url: "http://192.168.1.10:8080"
- url: "http://192.168.1.11:8080"
[http.services.sticky-service.loadBalancer]
[[http.services.sticky-service.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[[http.services.sticky-service.loadBalancer.servers]]
url = "http://192.168.1.11:8080"
[http.services.sticky-service.loadBalancer.sticky.cookie]
name = "server_id"
secure = true
httpOnly = true
sameSite = "lax"
name
string
default:"auto-generated"
Cookie name for session affinity
Only send cookie over HTTPS
Prevent JavaScript access to cookie
SameSite policy: none, lax, or strict
Health Checks
Automatically detect and remove unhealthy servers:
http:
services:
monitored-service:
loadBalancer:
healthCheck:
path: "/health"
interval: "10s"
timeout: "3s"
scheme: "http"
port: 8080
hostname: "localhost"
followRedirects: true
headers:
X-Health-Check: "true"
servers:
- url: "http://192.168.1.10:8080"
- url: "http://192.168.1.11:8080"
[http.services.monitored-service.loadBalancer]
[[http.services.monitored-service.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[[http.services.monitored-service.loadBalancer.servers]]
url = "http://192.168.1.11:8080"
[http.services.monitored-service.loadBalancer.healthCheck]
path = "/health"
interval = "10s"
timeout = "3s"
scheme = "http"
port = 8080
hostname = "localhost"
followRedirects = true
[http.services.monitored-service.loadBalancer.healthCheck.headers]
X-Health-Check = "true"
URL path for health check endpoint
Time between health checks
Maximum time to wait for health check response
Override server scheme for health checks
Override server port for health checks
Advanced Service Types
Weighted Round Robin Service
Load balance between multiple services:
http:
services:
canary-deployment:
weighted:
services:
- name: stable-version
weight: 90
- name: canary-version
weight: 10
stable-version:
loadBalancer:
servers:
- url: "http://192.168.1.10:8080"
canary-version:
loadBalancer:
servers:
- url: "http://192.168.1.20:8080"
[http.services.canary-deployment.weighted]
[[http.services.canary-deployment.weighted.services]]
name = "stable-version"
weight = 90
[[http.services.canary-deployment.weighted.services]]
name = "canary-version"
weight = 10
[http.services.stable-version.loadBalancer]
[[http.services.stable-version.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[http.services.canary-version.loadBalancer]
[[http.services.canary-version.loadBalancer.servers]]
url = "http://192.168.1.20:8080"
Mirroring Service
Mirror traffic to a second service for testing:
http:
services:
mirrored:
mirroring:
service: production
mirrorBody: true
maxBodySize: 1048576 # 1MB
mirrors:
- name: testing
percent: 10
production:
loadBalancer:
servers:
- url: "http://192.168.1.10:8080"
testing:
loadBalancer:
servers:
- url: "http://192.168.1.20:8080"
[http.services.mirrored.mirroring]
service = "production"
mirrorBody = true
maxBodySize = 1048576
[[http.services.mirrored.mirroring.mirrors]]
name = "testing"
percent = 10
[http.services.production.loadBalancer]
[[http.services.production.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[http.services.testing.loadBalancer]
[[http.services.testing.loadBalancer.servers]]
url = "http://192.168.1.20:8080"
Mirroring only copies requests to the mirror service. Responses from mirrors are discarded.
Failover Service
Automatically switch to fallback when main service fails:
http:
services:
resilient:
failover:
service: primary
fallback: backup
primary:
loadBalancer:
healthCheck:
path: "/health"
interval: "10s"
servers:
- url: "http://192.168.1.10:8080"
backup:
loadBalancer:
servers:
- url: "http://192.168.1.20:8080"
[http.services.resilient.failover]
service = "primary"
fallback = "backup"
[http.services.primary.loadBalancer]
[http.services.primary.loadBalancer.healthCheck]
path = "/health"
interval = "10s"
[[http.services.primary.loadBalancer.servers]]
url = "http://192.168.1.10:8080"
[http.services.backup.loadBalancer]
[[http.services.backup.loadBalancer.servers]]
url = "http://192.168.1.20:8080"
TCP Services
Configure TCP backend services:
tcp:
services:
database:
loadBalancer:
servers:
- address: "192.168.1.10:5432"
- address: "192.168.1.11:5432"
[tcp.services.database.loadBalancer]
[[tcp.services.database.loadBalancer.servers]]
address = "192.168.1.10:5432"
[[tcp.services.database.loadBalancer.servers]]
address = "192.168.1.11:5432"
TCP services use address (IP:Port) instead of url like HTTP services.
Complete Example
http:
services:
# Production service with health checks
production-api:
loadBalancer:
strategy: "p2c"
passHostHeader: true
sticky:
cookie:
name: "api_server"
secure: true
httpOnly: true
healthCheck:
path: "/health"
interval: "10s"
timeout: "3s"
headers:
Authorization: "Bearer health-check-token"
servers:
- url: "http://192.168.1.10:8080"
weight: 2
- url: "http://192.168.1.11:8080"
weight: 2
- url: "http://192.168.1.12:8080"
weight: 1
# Canary deployment
canary:
weighted:
sticky:
cookie:
name: "version"
services:
- name: production-api
weight: 95
- name: beta-api
weight: 5
beta-api:
loadBalancer:
healthCheck:
path: "/health"
interval: "10s"
servers:
- url: "http://192.168.1.20:8080"
# Mirrored for testing
mirrored-api:
mirroring:
service: production-api
maxBodySize: 2097152 # 2MB
mirrors:
- name: staging-api
percent: 10
staging-api:
loadBalancer:
servers:
- url: "http://192.168.1.30:8080"