Traefik is a reverse proxy designed to play with containers (docker or Kubernetes). However, it is possible to use Traefik with its binary and take advantage of its features in systems which don't have containers.

The interest of using the binary instead of the container can be discussed for a long time, but it's not the objective here. No presentation around Traefik in this documentation, you can read it here.

System preparation

Start by download the binary from the official GitHub repository : I'll use the 2.6.6 version in a VM, which is a Debian 11.2. Tests were done too, with success in an Ubuntu 20.04.2.

cd /tmp && wget && tar xzvf traefik_v2.6.6_linux_amd64.tar.gz

To quickly test its functions, start the binary and look at the listening port on your machine:

ss -ntlp # should give this informations :

LISTEN  0       128                  *:80                  *:*      users:(("traefik",pid=450,fd=3))  

Without configuration file or option, Traefik will listen (by default) on the port 80/TCP. There is no automatic redirection, no TLS section, no redirection to your internal services, no dashboard…

Let's copy the binary to a specific path, with the needed rights for “root”:

cp /tmp/traefik /usr/bin/.
chown root: /usr/bin/traefik
chmod 755 /usr/bin/traefik

User root is mandatory. Indeed, Traefik needs to have some system privileges to listen to system ports, like 80 and 443. If you have an idea to use Traefik without root, let's type it in the comment section !

Like docker version, Traefik is owned by the user “traefik” — its default folder is /etc/traefik for its configuration files. After downloading the binary, you have to create this configuration (example):

groupadd traefik
useradd -g traefik --no-user-group -d /etc/traefik --no-create-home -s /usr/sbin/nologin -r traefik

mkdir -p /etc/traefik/dynamic
chown -R traefik: /etc/traefik/.

touch /var/log/traefik.log && chown traefik: /var/log/traefik.log

In my precedent configuration files for Traefik, I used to use the path /etc/traefik/dynamic to store dynamic configuration files.

Log file are in the folder/var/log, which is the default path. Principal configuration file of Traefik is in the folder /etc/traefik.

Traefik preparation

Create the configuration file “/etc/traefik/traefik.yml”:

  sendAnonymousUsage: false
  checkNewVersion: false

  dashboard: true

  dashboard: false

  filePath: "/var/log/traefik.log"
  format: json
  level: "ERROR"

    directory: "/etc/traefik/dynamic"
    watch: true

    address: ":80"
          #to: websecure
          #scheme: https
    address: ":443"

I comment the block about the automatic redirection from HTTP to HTTPS. This bloc is not mandatory for the first start.

Now, create the systemd file in the path /lib/systemd/system/. Here's the content of the file traefik.service :

# /lib/systemd/system/traefik.service
Description=traefik service

ExecStart=/usr/bin/traefik --configFile=/etc/traefik/traefik.yml


Give it some rights and update the systemd index :

chown root: /lib/systemd/system/traefik.service && chmod 644 /lib/systemd/system/traefik.service

systemctl daemon-reload && systemctl start traefik.service

Now, Traefik is up and ready to forward some requests. The configuration file traefik.yml I typed in this post is simple but ready to go.

To access to the dashboard, open your navigator and type the IP of Traefik with its port 8080. Now it's time to configure your services…!

traefik dashboard
Traefik dashboard

Bonus – Ansible

Manual installation is a step to learn and try. I created an Ansible role to install Traefik, which is a resume of this post. You can take it in this GitHub repository :

Partager l'article