Traefik & KV Stores¶
Configuration Examples¶
Configuring KV Store & Deploying / Exposing one Service
Enabling a KV store provider (example: Consul)
providers:
consul:
endpoints:
- "127.0.0.1:8500"[providers.consul]
endpoints = ["127.0.0.1:8500"]--providers.consul.endpoints=127.0.0.1:8500Setting keys in the KV store (example: Consul)
consul kv put traefik/http/routers/my-router/rule "Host(`example.com`)"
consul kv put traefik/http/routers/my-router/service "my-service"
consul kv put traefik/http/services/my-service/loadbalancer/servers/0/url "http://127.0.0.1:8080"
Specify a Custom Port for the Service
Forward requests for http://example.com to http://127.0.0.1:12345:
consul kv put traefik/http/routers/my-router/rule "Host(`example.com`)"
consul kv put traefik/http/routers/my-router/service "my-service"
consul kv put traefik/http/services/my-service/loadbalancer/servers/0/url "http://127.0.0.1:12345"
Specifying more than one router and service
Forwarding requests to more than one service requires defining multiple routers and services.
In this example, requests are forwarded for http://example-a.com to http://127.0.0.1:8000 in addition to http://example-b.com forwarding to http://127.0.0.1:9000:
consul kv put traefik/http/routers/www-router/rule "Host(`example-a.com`)"
consul kv put traefik/http/routers/www-router/service "www-service"
consul kv put traefik/http/services/www-service/loadbalancer/servers/0/url "http://127.0.0.1:8000"
consul kv put traefik/http/routers/admin-router/rule "Host(`example-b.com`)"
consul kv put traefik/http/routers/admin-router/service "admin-service"
consul kv put traefik/http/services/admin-service/loadbalancer/servers/0/url "http://127.0.0.1:9000"
Configuration Options¶
Keys
Keys are case-insensitive.
HTTP¶
Routers¶
The character @ is not authorized in the router name <router_name>.
Services¶
The character @ is not authorized in the service name <service_name>.
Middleware¶
Configuration Options¶
| Key (Path) | Description | Value |
|---|---|---|
traefik/http/middlewares/mymiddleware/middleware_type/middleware_option |
With middleware_type the type of middleware (ex: forwardAuth, headers, etc)and middleware_option the middleware option to set (ex for the middleware addPrefix: prefix).More information about available middlewares in the dedicated middlewares section. |
foobar |
The character @ is not authorized in the middleware name.
Conflicts in Declaration
If you declare multiple middleware with the same name but with different parameters, the middleware fails to be declared.
ServerTransport¶
Configuration Options¶
| Key (Path) | Description | Value |
|---|---|---|
traefik/http/serversTransports/<serversTransportName>/st_option |
With st_option the ServerTransport option to set (ex maxIdleConnsPerHost).More information about available options in the dedicated ServerTransport section. |
ServerTransport Options |
TCP¶
You can declare TCP Routers and/or Services using KV.
Routers¶
Services¶
| Key (Path) | Description | Value |
|---|---|---|
traefik/tcp/services/mytcpservice/loadbalancer/servers/0/address |
See servers for more information. | xx.xx.xx.xx:xx |
traefik/tcp/services/mytcpservice/loadbalancer/servers/0/tls |
See servers for more information. | true |
traefik/tcp/services/myservice/loadbalancer/serverstransport |
Allows to reference a ServersTransport resource that is defined either with the File provider or the Kubernetes CRD one. See serverstransport for more information. |
foobar@file |
traefik/tcp/services/<service_name>/weighted/services/0/name |
See Service for more information. | foobar |
traefik/tcp/services/<service_name>/weighted/services/0/weight |
See Service for more information. | 42 |
Middleware¶
Configuration Options¶
You can declare pieces of middleware using tags starting with traefik/tcp/middlewares/{name-of-your-choice}., followed by the middleware type/options.
For example, to declare a middleware InFlightConn named test-inflightconn, you'd write traefik/tcp/middlewares/test-inflightconn/inflightconn/amount=10.
More information about available middlewares in the dedicated middlewares section.
| Key (Path) | Description | Value |
|---|---|---|
traefik/tcp/middlewares/mymiddleware/middleware_type/middleware_option |
With middleware_type the type of middleware (ex: inflightconn)and middleware_option the middleware option to set (ex for the middleware inflightconn: amount).More information about available middlewares in the dedicated middlewares section. |
foobar |
Conflicts in Declaration
If you declare multiple middleware with the same name but with different parameters, the middleware fails to be declared.
ServerTransport¶
Configuration Options¶
| Key (Path) | Description | Value |
|---|---|---|
traefik/tcp/serversTransports/<serversTransportName>/st_option |
With st_option the ServerTransport option to set (ex maxIdleConnsPerHost).More information about available options in the dedicated ServerTransport section. |
ServerTransport Options |
UDP¶
You can declare UDP Routers and/or Services using KV.
Routers¶
| Key (Path) | Description | Value |
|---|---|---|
traefik/udp/routers/myudprouter/entrypoints/0 |
See UDP Router for more information. | foobar |
traefik/udp/routers/myudprouter/service |
See UDP Router for more information. | foobar |
Services¶
| Key (Path) | Description | Value |
|---|---|---|
traefik/udp/services/loadBalancer/servers/<n>/address |
See UDP Service for more information. | foobar |
traefik/udp/services/weighted/services/0/name |
See UDP Service for more information. | foobar |
traefik/udp/services/weighted/servers/0/weight |
See UDP Service for more information. | 42 |
TLS¶
TLS Options¶
With the KV provider, you configure some parameters of the TLS connection using the tls/options key.
For example, you can define a basic setup like this:
| Key (Path) | Description | Value |
|---|---|---|
traefik/tls/options/Options0/alpnProtocols/0 |
See TLS Options for more information. | foobar |
traefik/tls/options/Options0/cipherSuites/0 |
See TLS Options for more information. | foobar |
traefik/tls/options/Options0/clientAuth/caFiles/0 |
See TLS Options for more information. | foobar |
traefik/tls/options/Options0/disableSessiontickets |
See TLS Options for more information. | true |
TLS Default Generated Certificates¶
You can configure Traefik to use an ACME provider (like Let's Encrypt) to generate the default certificate.
The configuration to resolve the default certificate should be defined in a TLS store.
| Key (Path) | Description | Value |
|---|---|---|
traefik/tls/stores/Store0/defaultGeneratedCert/domain/main |
See TLS for more information. | foobar |
traefik/tls/stores/Store0/defaultGeneratedCert/domain/sans/0 |
See TLS for more information | foobar |
traefik/tls/stores/Store0/defaultGeneratedCert/domain/sans/1 |
See TLS for more information | foobar |
traefik/tls/stores/Store0/defaultGeneratedCert/resolver |
See TLS for more information | foobar |