Web / Traefik Interview questions
How do you write and load a custom Traefik plugin using Yaegi?
Traefik plugins are written in Go but run through Yaegi, an embedded Go interpreter, rather than being compiled into the Traefik binary, which lets plugins load and update without rebuilding or restarting Traefik itself.
A plugin implements a standard interface: a constructor function and a ServeHTTP method that receives the request, can inspect or modify it, and then calls the next handler in the chain, following the same middleware pattern Traefik uses internally.
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) { return &MyPlugin{next: next, name: name}, nil } func (p *MyPlugin) ServeHTTP(rw http.ResponseWriter, req *http.Request) { req.Header.Set("X-Custom", "value") p.next.ServeHTTP(rw, req) }
Plugins are declared in the static configuration under experimental.plugins, pointing at a module name and version pulled from the Plugin Catalog (or a local plugin during development), and are then used just like any built-in middleware by referencing the plugin's type in a middleware definition.
Because Yaegi interprets rather than compiles the plugin code, it trades some runtime performance for the safety of not needing arbitrary compiled code baked into the core Traefik binary, which matters for a proxy sitting at the edge of untrusted traffic.
More Related questions...