I recently made the switch from the nginx reverse proxy life to Traefik. I've written a couple of other posts recently about the process:

Today's post is going to cover the final piece of the jigsaw I needed to solve before I could dump nginx, the file provider. In otherwords - how do I use Traefik to route traffic for services that aren't containers or published via another service discovery backend? In the case of this post it's Home Assistant and Blue Iris. Two critical services in my LAN that run on dedicated hardware.

As always, code can be found at github.com/ironicbadger/infra.

File Provider

Traefik discourage use of the file provider, a quick google on the topc and you'll discover they think it is orthogonal to overall goals of the project. As such, the documentation is a little crypic so here's how I use it.

When I run Traefik I mount /etc/traefik to a volume on the host. In that volume create a file called rules.yaml. Here is what that file looks like:

http:
  routers:
    router-homeassistant:
      entryPoints:
        - websecure
      rule: Host(`ha.123.com`)
      service: service-homeassistant
      tls:
        certResolver: cloudflare
    router-blueiris:
      entryPoints:
        - websecure
      rule: Host(`bi.123.com`)
      service: service-blueiris
      tls:
        certResolver: cloudflare
  services:
    service-homeassistant:
      loadBalancer:
        servers:
        - url: "http://192.168.1.99:8123"
    service-blueiris:
      loadBalancer:
        servers:
        - url: "http://192.168.1.200:81"

This file defines routers and services, terms you should be familiar with when working with Traefik.

This file is case sensitive. I lost most of an afternoon because certresolver is not the same as certResolver and so on.

The syntax for defining the rules to match is the same here as it would be if you were applying the label http.routers.routername.rule=Host(`bi.ktz.me`). This is how to determine the structure of the keys in this file.

/etc/traefik.yaml

Finally, you'll need to tell Traefik to use this file in /etc/traefik.yaml. This is configured under the providers key:

providers:
    docker:
        endpoint: unix:///var/run/docker.sock
        watch: true
        exposedByDefault: false
    file:
      filename: /etc/traefik/rules.yaml

And there we are, that's how to configure an external service to work with Traefik v2.