1+ # this traefik reverse proxy has a bunch of features:
2+ # - reverse proxy all 80/443 ingress traffic on a swarm
3+ # - dynamic config via each app's swarm service labels
4+ # - HA multi-container design for traefik
5+ # - runs traefik on host NIC directly, to improve performance
6+ # and capture client IP's
7+ # - uses consul to store static config for startup
8+ # - uses haproxy to allow offloading traefik to worker nodes
9+ # - store consul data in a volume on cloud storage with rexray
10+
11+ # TODO improvements
12+ # make consul HA
13+ # properly handle service restarts if init container config changes
14+ # use envvars for email and default domain settings
15+
16+ version : ' 3.7'
17+
18+ x-default-opts :
19+ &default-opts
20+ logging :
21+ options :
22+ max-size : " 1m"
23+ # driver: "gelf"
24+ # options:
25+ # gelf-address: "udp://127.0.0.1:5000"
26+
27+ services :
28+
29+ traefik-init :
30+ << : *default-opts
31+ image : traefik:1.7-alpine
32+ networks :
33+ - traefik-consul
34+ command :
35+ # Use your favourite settings here, but add:
36+ - storeconfig
37+ - --api
38+ # NOTE: you'll want to lower this logLevel for real word stuff
39+ - --logLevel="DEBUG"
40+ # NOTE: you'll want to disable this for anything of signifant traffic, or route logs outside stdout
41+ - --accessLog
42+ - --docker
43+ - --docker.endPoint=http://dockersocket:2375
44+ - --docker.swarmMode
45+ - --docker.domain=traefik
46+ - --docker.watch
47+ - --consul
48+ - --consul.endpoint=consul:8500
49+ - --consul.prefix=traefik
50+ - --defaultentrypoints=http,https
51+ - --entryPoints=Name:https Address::443 TLS
52+ - --entryPoints=Name:http Address::80
53+ # - --acme
54+ # - --acme.email=${TRAEFIK_ACME_EMAIL}
55+ # # TODO: envvar for email and default domain
56+ # - --acme.httpchallenge
57+ # - --acme.httpchallenge.entrypoint=http
58+ # - --acme.onhostrule=true
59+ # - --acme.entrypoint=https
60+ # - --acme.storage=my/key
61+ # - --acme.acmelogging
62+ # - --acme.caserver=https://acme-staging-v02.api.letsencrypt.org/directory
63+ # - --acme.caserver=https://acme-v02.api.letsencrypt.org/directory
64+ deploy :
65+ restart_policy :
66+ condition : on-failure
67+
68+ traefik :
69+ << : *default-opts
70+ image : traefik:1.7-alpine
71+ networks :
72+ - proxy
73+ - traefik-consul
74+ - traefik-docker
75+ ports :
76+ - target : 80
77+ published : 80
78+ protocol : tcp
79+ mode : host
80+ - target : 443
81+ published : 443
82+ protocol : tcp
83+ mode : host
84+ - target : 8080
85+ published : 8080
86+ protocol : tcp
87+ mode : ingress # traefik dashboard
88+ command :
89+ - --consul
90+ - --consul.endpoint=consul:8500
91+ - --consul.prefix=traefik
92+ deploy :
93+ mode : global
94+ # if you have enough servers, make this only run on workers, maybe in a public DMZ
95+ # placement:
96+ # constraints: [node.role == worker]
97+
98+ consul :
99+ << : *default-opts
100+ image : consul
101+ command : agent -server -bootstrap-expect=1
102+ networks :
103+ - traefik-consul
104+ volumes :
105+ - consul:/consul/data
106+ environment :
107+ - CONSUL_LOCAL_CONFIG={"server":true}
108+ - CONSUL_BIND_INTERFACE=eth0
109+ - CONSUL_CLIENT_INTERFACE=eth0
110+
111+ # this custom haproxy allows us to move traefik to worker nodes
112+ # while this container listens on managers and only allows
113+ # traefik to connect, read-only, to limited docker api calls
114+ # https://github.com/Tecnativa/docker-socket-proxy
115+ dockersocket :
116+ << : *default-opts
117+ image : tecnativa/docker-socket-proxy
118+ networks :
119+ - traefik-docker
120+ volumes :
121+ - /var/run/docker.sock:/var/run/docker.sock
122+ environment :
123+ # CONTAINERS: 1
124+ NETWORKS : 1
125+ SERVICES : 1
126+ # SWARM: 1
127+ TASKS : 1
128+ deploy :
129+ mode : global
130+ placement :
131+ constraints : [node.role == manager]
132+
133+ volumes :
134+ consul :
135+ driver : ${DOCKER_VOL_DRIVER:-local}
136+ # for example set DOCKER_VOL_DRIVER="rexray/dobs"
137+ driver_opts :
138+ size : 1
139+
140+ networks :
141+ ntw_front :
142+ driver : overlay
143+ driver_opts :
144+ encrypted : ' true'
145+
146+ traefik-consul :
147+ driver : overlay
148+ driver_opts :
149+ encrypted : ' true'
150+ # since we're passing SSL certs over TCP, lets IPSec
151+
152+ traefik-docker :
153+ driver : overlay
154+ driver_opts :
155+ encrypted : ' true'
156+ # since we're passing docker socket stuff over TCP, lets IPSec
0 commit comments