traefik/docs/configuration/backends/consul.md

151 lines
7 KiB
Markdown
Raw Normal View History

# Consul Backend
2017-08-25 19:32:33 +00:00
## Consul Key-Value backend
2017-09-11 17:10:04 +00:00
Træfik can be configured to use Consul as a backend configuration.
2017-08-25 19:32:33 +00:00
```toml
################################################################
# Consul KV configuration backend
################################################################
2017-09-11 17:10:04 +00:00
# Enable Consul KV configuration backend.
2017-08-25 19:32:33 +00:00
[consul]
2017-09-11 17:10:04 +00:00
# Consul server endpoint.
2017-08-25 19:32:33 +00:00
#
# Required
2017-09-11 17:10:04 +00:00
# Default: "127.0.0.1:8500"
2017-08-25 19:32:33 +00:00
#
endpoint = "127.0.0.1:8500"
2017-09-11 17:10:04 +00:00
# Enable watch Consul changes.
2017-08-25 19:32:33 +00:00
#
# Optional
2017-09-11 17:10:04 +00:00
# Default: true
2017-08-25 19:32:33 +00:00
#
watch = true
# Prefix used for KV store.
#
# Optional
2017-09-11 17:10:04 +00:00
# Default: traefik
2017-08-25 19:32:33 +00:00
#
prefix = "traefik"
2017-09-11 17:10:04 +00:00
# Override default configuration template.
# For advanced users :)
2017-08-25 19:32:33 +00:00
#
# Optional
#
# filename = "consul.tmpl"
2017-09-11 17:10:04 +00:00
# Use Consul user/pass authentication.
2017-08-25 19:32:33 +00:00
#
# Optional
#
2017-09-11 17:10:04 +00:00
# username = foo
# password = bar
# Enable Consul TLS connection.
#
# Optional
#
# [consul.tls]
# ca = "/etc/ssl/ca.crt"
# cert = "/etc/ssl/consul.crt"
# key = "/etc/ssl/consul.key"
# insecureskipverify = true
2017-08-25 19:32:33 +00:00
```
2017-09-11 17:10:04 +00:00
To enable constraints see [backend-specific constraints section](/configuration/commons/#backend-specific).
Please refer to the [Key Value storage structure](/user-guide/kv-config/#key-value-storage-structure) section to get documentation on Traefik KV structure.
## Consul Catalog backend
2017-08-25 19:32:33 +00:00
2017-09-11 17:10:04 +00:00
Træfik can be configured to use service discovery catalog of Consul as a backend configuration.
2017-08-25 19:32:33 +00:00
```toml
################################################################
# Consul Catalog configuration backend
################################################################
2017-09-11 17:10:04 +00:00
# Enable Consul Catalog configuration backend.
2017-08-25 19:32:33 +00:00
[consulCatalog]
2017-09-11 17:10:04 +00:00
# Consul server endpoint.
2017-08-25 19:32:33 +00:00
#
# Required
2017-09-11 17:10:04 +00:00
# Default: "127.0.0.1:8500"
2017-08-25 19:32:33 +00:00
#
endpoint = "127.0.0.1:8500"
2017-09-11 17:10:04 +00:00
# Expose Consul catalog services by default in Traefik.
2017-08-25 19:32:33 +00:00
#
# Optional
2017-09-11 17:10:04 +00:00
# Default: true
2017-08-25 19:32:33 +00:00
#
exposedByDefault = false
2017-09-11 17:10:04 +00:00
# Prefix for Consul catalog tags.
2017-08-25 19:32:33 +00:00
#
# Optional
2017-09-11 17:10:04 +00:00
# Default: "traefik"
2017-08-25 19:32:33 +00:00
#
prefix = "traefik"
2017-09-11 17:10:04 +00:00
# Default frontEnd Rule for Consul services.
#
# The format is a Go Template with:
# - ".ServiceName", ".Domain" and ".Attributes" available
# - "getTag(name, tags, defaultValue)", "hasTag(name, tags)" and "getAttribute(name, tags, defaultValue)" functions are available
# - "getAttribute(...)" function uses prefixed tag names based on "prefix" value
2017-08-25 19:32:33 +00:00
#
# Optional
2017-09-11 17:10:04 +00:00
# Default: "Host:{{.ServiceName}}.{{.Domain}}"
2017-08-25 19:32:33 +00:00
#
#frontEndRule = "Host:{{.ServiceName}}.{{Domain}}"
2017-08-25 19:32:33 +00:00
```
2017-09-11 17:10:04 +00:00
This backend will create routes matching on hostname based on the service name used in Consul.
To enable constraints see [backend-specific constraints section](/configuration/commons/#backend-specific).
### Tags
2017-08-25 19:32:33 +00:00
2017-09-11 17:10:04 +00:00
Additional settings can be defined using Consul Catalog tags.
2017-08-25 19:32:33 +00:00
2017-10-10 13:24:03 +00:00
| Tag | Description |
|-----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `traefik.enable=false` | Disable this container in Træfik |
| `traefik.protocol=https` | Override the default `http` protocol |
| `traefik.backend.weight=10` | Assign this weight to the container |
| `traefik.backend.circuitbreaker=EXPR` | Create a [circuit breaker](/basics/#backends) to be used against the backend, ex: `NetworkErrorRatio() > 0.` |
| `traefik.backend.maxconn.amount=10` | Set a maximum number of connections to the backend. Must be used in conjunction with the below label to take effect. |
| `traefik.backend.maxconn.extractorfunc=client.ip` | Set the function to be used against the request to determine what to limit maximum connections to the backend by. Must be used in conjunction with the above label to take effect. |
| `traefik.frontend.rule=Host:test.traefik.io` | Override the default frontend rule (Default: `Host:{{.ServiceName}}.{{.Domain}}`). |
| `traefik.frontend.passHostHeader=true` | Forward client `Host` header to the backend. |
| `traefik.frontend.priority=10` | Override default frontend priority |
| `traefik.frontend.entryPoints=http,https` | Assign this frontend to entry points `http` and `https`. Overrides `defaultEntryPoints`. |
| `traefik.frontend.auth.basic=EXPR` | Sets basic authentication for that frontend in CSV format: `User:Hash,User:Hash` |
| `traefik.backend.loadbalancer=drr` | override the default `wrr` load balancer algorithm |
| `traefik.backend.loadbalancer.stickiness=true` | enable backend sticky sessions |
| `traefik.backend.loadbalancer.stickiness.cookieName=NAME` | Manually set the cookie name for sticky sessions |
| `traefik.backend.loadbalancer.sticky=true` | enable backend sticky sessions (DEPRECATED) |
2017-11-30 09:12:03 +00:00
### Examples
If you want that Træfik uses Consul tags correctly you need to defined them like that:
```json
traefik.enable=true
traefik.tags=api
traefik.tags=external
```
If the prefix defined in Træfik configuration is `bla`, tags need to be defined like that:
```json
bla.enable=true
bla.tags=api
bla.tags=external
```