Categories
DevOps Networking Server

Traefik 2.5 quick-start guide

How to use TOML, YAML, or Docker Labels to hit the ground running with Traefik 2.5 under Docker Compose.

Introduction

2022-04-01:

Please note: Traefik version 2 has pushed new minor versions since this article was published, and doesn’t have a “v2” tag to simplify use.

Please check Traefik’s images on Docker Hub for the latest minor version of version 2.

Trying to learn the basics of Traefik to get a working configuration deployed can be a bit of a bear, and a constant pain point for many. Time permitting, I try to answer people’s questions when I can, so I figured that this article might help reduce the barrier to entry for people trying to grasp the fundamental concepts of Traefik 2.5.

If you haven’t heard of Traefik, please allow me to quote directly from the source:

Traefik (pronounced traffic) is a modern HTTP reverse proxy and load balancer that makes deploying microservices easy. Traefik integrates with your existing infrastructure components (Docker, Swarm mode, Kubernetes, Marathon, Consul, Etcd, Rancher, Amazon ECS, …) and configures itself automatically and dynamically.

Traefik GitHub repository

Prerequisites

Configuration types

It can be a bit confusing, but Traefik has two configuration types:

  1. Startup (referred to as the static configuration).
    1. Sets up connections to providers (e.g. Docker, Consul, the file system, etc.)
    2. Defines entrypoints (in other words, ports and protocols such as HTTP and HTTPS) that Traefik will listen to.
  2. Routing (referred to as the dynamic configuration), where changes are hot-reloaded (e.g. swapping or scaling backend servers without interrupting service to your audience).

Configuration formats

Initially, Traefik started with the TOML format but, thankfully, added support for the YAML format with version 2.0’s release in September 2019. In this article, I’ve provided both TOML and YAML implementations for comparison. Use what works best for you.

I considered writing this article only with YAML, but so many of the examples on the Internet are in the TOML format, and the Docker labels options for Traefik have a similar (if not identical) syntax. Since this article is geared towards helping people get over the learning curve as quickly as possible, I opted for the path of least resistance.

Encryption

Traefik supports the ability to generate/renew certificates from the Let’s Encrypt! Certificate Authority, but I use an administrative server to do this and then distribute them to my servers.

One reply on “Traefik 2.5 quick-start guide”

Leave a Reply

Your email address will not be published. Required fields are marked *