Support YAML for the dynamic configuration.
This commit is contained in:
parent
96962dd21f
commit
e69d4cba88
36 changed files with 1529 additions and 289 deletions
|
@ -3,10 +3,10 @@
|
|||
Good Old Configuration File
|
||||
{: .subtitle }
|
||||
|
||||
The file provider lets you define the [dynamic configuration](./overview.md) in a `toml` file.
|
||||
The file provider lets you define the [dynamic configuration](./overview.md) in a TOML or YAML file.
|
||||
You can write these configuration elements:
|
||||
|
||||
* At the end of the main Traefik configuration file (by default: `traefik.toml`).
|
||||
* At the end of the main Traefik configuration file (by default: `traefik.toml`/`traefik.yml`/`traefik.yaml`).
|
||||
* In [a dedicated file](#filename)
|
||||
* In [several dedicated files](#directory)
|
||||
|
||||
|
@ -20,10 +20,20 @@ You can write these configuration elements:
|
|||
|
||||
??? example "Declaring Routers, Middlewares & Services"
|
||||
|
||||
``` toml
|
||||
# Enabling the file provider
|
||||
[providers.file]
|
||||
Enabling the file provider:
|
||||
|
||||
```toml tab="TOML"
|
||||
[providers.file]
|
||||
```
|
||||
|
||||
```yaml tab="YAML"
|
||||
providers:
|
||||
file: {}
|
||||
```
|
||||
|
||||
Declaring Routers, Middlewares & Services:
|
||||
|
||||
```toml tab="TOML"
|
||||
[http]
|
||||
# Add the router
|
||||
[http.routers]
|
||||
|
@ -49,6 +59,32 @@ You can write these configuration elements:
|
|||
[[http.services.service-foo.LoadBalancer.Servers]]
|
||||
url = "http://bar/"
|
||||
```
|
||||
|
||||
```yaml tab="YAML"
|
||||
http:
|
||||
routers:
|
||||
router0:
|
||||
entrypoints:
|
||||
- web
|
||||
middlewares:
|
||||
- my-basic-auth
|
||||
service: service-foo
|
||||
rule: Path(`foo`)
|
||||
middlewares:
|
||||
my-basic-auth:
|
||||
basicAuth:
|
||||
users:
|
||||
- test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/
|
||||
- test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0
|
||||
usersfile: etc/traefik/.htpasswd
|
||||
headerfield: ""
|
||||
services:
|
||||
service-foo:
|
||||
loadbalancer:
|
||||
servers:
|
||||
- url: http://foo/
|
||||
- url: http://bar/
|
||||
```
|
||||
|
||||
## Provider Configuration Options
|
||||
|
||||
|
@ -61,24 +97,36 @@ _Optional_
|
|||
|
||||
Defines the path of the configuration file.
|
||||
|
||||
```toml
|
||||
```toml tab="TOML"
|
||||
[providers]
|
||||
[providers.file]
|
||||
filename = "rules.toml"
|
||||
```
|
||||
|
||||
```yaml tab="YAML"
|
||||
providers:
|
||||
file:
|
||||
filename: rules.yaml
|
||||
```
|
||||
|
||||
### `directory`
|
||||
|
||||
_Optional_
|
||||
|
||||
Defines the directory that contains the configuration files.
|
||||
|
||||
```toml
|
||||
```toml tab="TOML"
|
||||
[providers]
|
||||
[providers.file]
|
||||
directory = "/path/to/config"
|
||||
```
|
||||
|
||||
```yaml tab="YAML"
|
||||
providers:
|
||||
file:
|
||||
directory: /path/to/config
|
||||
```
|
||||
|
||||
### `watch`
|
||||
|
||||
_Optional_
|
||||
|
@ -86,24 +134,32 @@ _Optional_
|
|||
Set the `watch` option to `true` to allow Traefik to automatically watch for file changes.
|
||||
It works with both the `filename` and the `directory` options.
|
||||
|
||||
```toml
|
||||
```toml tab="TOML"
|
||||
[providers]
|
||||
[providers.file]
|
||||
filename = "rules.toml"
|
||||
watch = true
|
||||
```
|
||||
|
||||
### TOML Templating
|
||||
```yaml tab="YAML"
|
||||
providers:
|
||||
file:
|
||||
filename: rules.yml
|
||||
watch: true
|
||||
```
|
||||
|
||||
### Go Templating
|
||||
|
||||
!!! warning
|
||||
TOML templating only works along with dedicated configuration files. Templating does not work in the Traefik main configuration file.
|
||||
Go Templating only works along with dedicated configuration files.
|
||||
Templating does not work in the Traefik main configuration file.
|
||||
|
||||
Traefik allows using TOML templating.
|
||||
Traefik allows using Go templating.
|
||||
Thus, it's possible to define easily lot of routers, services and TLS certificates as described in the file `template-rules.toml` :
|
||||
|
||||
??? example "Configuring Using Templating"
|
||||
|
||||
```toml
|
||||
|
||||
```toml tab="TOML"
|
||||
# template-rules.toml
|
||||
[http]
|
||||
|
||||
|
@ -149,3 +205,43 @@ Thus, it's possible to define easily lot of routers, services and TLS certificat
|
|||
# ...
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
```yaml tab="YAML"
|
||||
http:
|
||||
|
||||
{{range $i, $e := until 100 }}
|
||||
routers:
|
||||
router{{ $e }:
|
||||
# ...
|
||||
{{end}}
|
||||
|
||||
{{range $i, $e := until 100 }}
|
||||
services:
|
||||
application{{ $e }}:
|
||||
# ...
|
||||
{{end}}
|
||||
|
||||
tcp:
|
||||
|
||||
{{range $i, $e := until 100 }}
|
||||
routers:
|
||||
router{{ $e }:
|
||||
# ...
|
||||
{{end}}
|
||||
|
||||
{{range $i, $e := until 100 }}
|
||||
services:
|
||||
service{{ $e }}:
|
||||
# ...
|
||||
{{end}}
|
||||
|
||||
{{ range $i, $e := until 10 }}
|
||||
tls:
|
||||
store:
|
||||
- "my-store-foo-{{ $e }}"
|
||||
- "my-store-bar-{{ $e }}"
|
||||
certificate:
|
||||
certfile: "/etc/traefik/cert-{{ $e }}.pem"
|
||||
keyfile: "/etc/traefik/cert-{{ $e }}.key"
|
||||
{{end}}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue