Wednesday, March 13, 2019

Traefik getting started

After previous post I've really wanted to get started and do some testing with Traefik.io. I started a bit on a wrong foot, but eventually all worked out fine. Many times, having some issues with a new tool or technology is best way to get you digging into the details and learn a lot.

For beginning I wanted to use it as a simple reverse proxy, similarly to NGINX. I installed Traefik locally (very simple, just an executable) and used my SiteGo test project, both as a simple local application and using Docker version:

docker run -t -i -p 8000:8000 ovicrisan/sitego

Then I created sitego.toml file needed for Traefik configuration, like this:

[entryPoints]
  [entryPoints.http]
  address = ":8081"
[frontends]
  [frontends.frontend1]
  backend = "backend1"
    [frontends.frontend1.routes.test_1]
    rule = "Host:localhost"
[backends]
  [backends.backend1]
    [backends.backend1.servers.server1]
    url = "http://localhost:8000"
[file]
#[api]

And start it locally with

traefik -c sitego.toml --accessLog

-c is for config file ('sitego.toml'), and --accessLog to show in terminal / console all requests.

Opening in the browser with http://localhost:8081 worked fine

Very important note here: don't forget [file] config setting, otherwise you'll get an 404 error ("page not found") with the message "backend not found". That setting will define a 'provider' which is necessary for all thing to work. There is another option to pass all config settings as parameters in command line (or Docker command), but for simple projects I prefer TOML file.

You can enable / disable [api] to access Web UI (dashboard) for metrics and stuff, then just load it at http://localhost:8080.

Intentionally I didn't want to use it from Docker container, no TLS (https) and other details, just to keep it to a bare minimum. I'll definitely use it for much more, including some ASP.NET Core microservices.

No comments:

Post a Comment