Traefik 2 : Contribution and Debug
This article is a follow-up to this one: https://dev.to/jadekharats/traefik-2-concept-3elj
The need
We need to add other services to our Traefik but especially to understand how it works to learn.
Debugging and logging
Everything will be done in the static configuration. Besides, I give you the link to the official documentation of the static configuration by file: https://docs.traefik.io/v2.0/reference/static-configuration/file/
Log activation
In the traefik.yaml
file we will add this block
log:
filePath: "log/traefik.log"
level: WARN
The WARN level is enough for my taste to understand the creations and configurations of Traefik 2 elements.
We will also add access.log
that we find for any reverse proxy
AccessLog:
filePath: "log/access.log"
bufferingSize: 100
Activate the debug mode of the API
To have the API actions in the log/traefik.log
log file, modify the api block as follows
api:
dashboard: true
debug: true
Recovery of logs outside the container
We want to get the logs out of the container. For that, nothing more simple, it is enough to declare the volume in the file stack-traefik.yml
services:
traefik:
volumes:
- /swarm/traefik2/log:/log
Update and anonymous contribution.
Traefik 2 is in Release Candidate version. It is therefore necessary to keep up to date and at the same time, allow Traefik to send anonymous data to the maintainers to help them develop the RC.
Again, it's in the traefik.yaml
that it's happening.
global:
checkNewVersion: true
sendAnonymousUsage: true
Conclusion.
Here we are ready for adding TLS and certificate generation.
As for the previous article, I put back, the state of the files at this stage.
traefik.yaml
global:
checkNewVersion: true
sendAnonymousUsage: true
api:
dashboard: true
debug: true
entrypoints:
ssh:
address: ":22"
http:
address: ":80"
https:
address: ":443"
providers:
docker:
watch: true
swarmMode: true
useBindPortIP: true
endpoint: "unix:///var/run/docker.sock"
log:
filePath: "log/traefik.log"
level: WARN
AccessLog:
filePath: "log/access.log"
bufferingSize: 100
stack-traefik.yml
version: "3.3"
Link:
traefik-net:
external: true
configs:
traefik.yaml:
file: ./traefik.yaml
services:
traefik:
image: traefik:v2.0
ports:
- 80:80
- 443:443
- 22:22
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- /swarm/traefik2/log:/log
configs:
- source: traefik.yaml
target: /etc/traefik/traefik.yaml
Link:
- traefik-net
deploy:
fashion: global
placement:
constraints: [node.role == manager]
labels:
- "traefik.docker.network=traefik-net"
- "traefik.http.routers.traefik-router0.entrypoints=http"
- "traefik.http.routers.traefik-router0.rule=Host(`traefik.example.tld`)"
- "traefik.http.routers.traefik-router0.middlewares=auth"
- "traefik.http.middlewares.auth.basicauth.users=jade:$$2y$$..."
- "traefik.http.services.traefik-service.loadbalancer.server.port=8080"
Top comments (0)