Using Plugins

Plugins are available to any instance of Traefik v2.3 or later that is registered with Traefik Pilot. Plugins are hosted on GitHub, but you can browse plugins to add to your registered Traefik instances from the Traefik Pilot UI.

Experimental Features

Plugins can potentially modify the behavior of Traefik in unforeseen ways. Exercise caution when adding new plugins to production Traefik instances.

Add a Plugin

To add a new plugin to a Traefik instance, you must modify that instance’s static configuration. The code to be added is provided by the Traefik Pilot UI when you choose Install the Plugin.

In the example below, we add the blockpath and rewritebody plugins:

File (TOML)

  1. [entryPoints]
  2. [entryPoints.web]
  3. address = ":80"
  4. [pilot]
  5. token = "xxxxxxxxx"
  6. [experimental.plugins]
  7. [experimental.plugins.block]
  8. modulename = "github.com/traefik/plugin-blockpath"
  9. version = "v0.2.0"
  10. [experimental.plugins.rewrite]
  11. modulename = "github.com/traefik/plugin-rewritebody"
  12. version = "v0.3.0"

File (YAML)

  1. entryPoints:
  2. web:
  3. address: :80
  4. pilot:
  5. token: xxxxxxxxx
  6. experimental:
  7. plugins:
  8. block:
  9. modulename: github.com/traefik/plugin-blockpath
  10. version: v0.2.0
  11. rewrite:
  12. modulename: github.com/traefik/plugin-rewritebody
  13. version: v0.3.0

CLI

  1. --entryPoints.web.address=:80
  2. --pilot.token=xxxxxxxxx
  3. --experimental.plugins.block.modulename=github.com/traefik/plugin-blockpath
  4. --experimental.plugins.block.version=v0.2.0
  5. --experimental.plugins.rewrite.modulename=github.com/traefik/plugin-rewritebody
  6. --experimental.plugins.rewrite.version=v0.3.0

Configuring Plugins

Some plugins will need to be configured by adding a dynamic configuration. For the bodyrewrite plugin, for example:

Docker

  1. labels:
  2. - "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].regex=example"
  3. - "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].replacement=test"

Kubernetes

  1. apiVersion: traefik.containo.us/v1alpha1
  2. kind: Middleware
  3. metadata:
  4. name: my-rewritebody
  5. spec:
  6. plugin:
  7. rewrite:
  8. rewrites:
  9. - regex: example
  10. replacement: test

Consul Catalog

  1. - "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].regex=example"
  2. - "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].replacement=test"

Marathon

  1. "labels": {
  2. "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].regex": "example",
  3. "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].replacement": "test"
  4. }

Rancher

  1. labels:
  2. - "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].regex=example"
  3. - "traefik.http.middlewares.my-rewritebody.plugin.rewrite.rewrites[0].replacement=test"

File (TOML)

  1. [http.middlewares]
  2. [http.middlewares.my-rewritebody.plugin.rewrite]
  3. lastModified = true
  4. [[http.middlewares.my-rewritebody.plugin.rewrite.rewrites]]
  5. regex = "example"
  6. replacement = "test"

File (YAML)

  1. http:
  2. middlewares:
  3. my-rewritebody:
  4. plugin:
  5. rewrite:
  6. rewrites:
  7. - regex: example
  8. replacement: test