What is Treafik?

The Treafik Project

In short: its a Web-Proxy like nginx or HAProxy.

Why: Id like to get to know it better, since its used in things like Kubernetes and similar fun things.

Installation

Unexposed tutorials

This setup should be production ready, thus we follow the HTTP(s) centric setup, including the setup of a basic-auth middleware. I am basicly following this tutorial : Setup with Docker

Pay attention that this doesnt setup SSL-Certs with a true provider. Details for this can be found here:

Exposed Tutorials

You can get started with the Exposing Services Tutorial.

Configuration

Since I want to configure everything via git, I am using the fileprovider. Documentation is sparse (imo) but I guess you can do it. Its the same as the docker-tags, simply written out into yaml/toml commands.

  1. You can configure middlewars, for example and https-redirect
  2. You have to configure routers, they define SSL certs process as well as which service the URL is supposed to be routed to. This can also include basic-auth things!
  3. The services define where the traffic should head. Mostl likely your web-server!

As an example, this is how this web-service is defined:

http:
  middlewares:
    https-redirect:
      redirectScheme:
        scheme: https
        permanent: true
 
  routers:
    itwoc_router:
      rule: "Host(`itwoc.de`)"
      service: itwoc_site
      entryPoints:
        - websecure
      tls:
        certResolver: dns01-challenge
  
    # ADD THIS: This handles HTTP traffic and redirects it
    itwoc_router_http:
      rule: "Host(`itwoc.de`)"
      entryPoints:
        - web
      middlewares:
        - https-redirect
      service: itwoc_site
 
 
  services:
    itwoc_site:
      loadBalancer:
        servers:
          - url: "http://hermes.itwoc.internal:80"