traefik/docs/content/providers/consul-catalog.md

604 lines
11 KiB
Markdown
Raw Normal View History

2019-10-15 15:34:08 +00:00
# Traefik & Consul Catalog
2019-11-29 16:16:05 +00:00
A Story of Tags, Services & Instances
2019-10-15 15:34:08 +00:00
{: .subtitle }
![Consul Catalog](../assets/img/providers/consul.png)
2019-11-29 16:16:05 +00:00
Attach tags to your services and let Traefik do the rest!
2019-10-15 15:34:08 +00:00
## Configuration Examples
??? example "Configuring Consul Catalog & Deploying / Exposing Services"
2019-11-29 16:16:05 +00:00
Enabling the consul catalog provider
2019-10-15 15:34:08 +00:00
```toml tab="File (TOML)"
2019-10-29 11:32:05 +00:00
[providers.consulCatalog]
2019-10-15 15:34:08 +00:00
```
```yaml tab="File (YAML)"
providers:
2019-10-29 11:32:05 +00:00
consulCatalog: {}
2019-10-15 15:34:08 +00:00
```
```bash tab="CLI"
--providers.consulcatalog=true
```
2019-11-29 16:16:05 +00:00
Attaching tags to services
2019-10-15 15:34:08 +00:00
```yaml
2019-11-29 16:16:05 +00:00
- traefik.http.services.my-service.rule=Host(`mydomain.com`)
2019-10-15 15:34:08 +00:00
```
## Routing Configuration
See the dedicated section in [routing](../routing/providers/consul-catalog.md).
## Provider Configuration
2019-10-31 10:56:05 +00:00
### `refreshInterval`
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
_Optional, Default=15s_
2019-10-15 15:34:08 +00:00
```toml tab="File (TOML)"
2019-10-29 11:32:05 +00:00
[providers.consulCatalog]
2019-10-31 10:56:05 +00:00
refreshInterval = "30s"
2019-10-15 15:34:08 +00:00
# ...
```
```yaml tab="File (YAML)"
providers:
2019-10-29 11:32:05 +00:00
consulCatalog:
2019-10-31 10:56:05 +00:00
refreshInterval: 30s
2019-10-15 15:34:08 +00:00
# ...
```
```bash tab="CLI"
2019-10-31 10:56:05 +00:00
--providers.consulcatalog.refreshInterval=30s
2019-10-15 15:34:08 +00:00
# ...
```
2019-10-31 10:56:05 +00:00
Defines the polling interval.
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
### `prefix`
2019-10-15 15:34:08 +00:00
2019-11-29 16:16:05 +00:00
_required, Default="traefik"_
2019-10-15 15:34:08 +00:00
```toml tab="File (TOML)"
2019-10-29 11:32:05 +00:00
[providers.consulCatalog]
2019-11-29 16:16:05 +00:00
prefix = "test"
2019-10-15 15:34:08 +00:00
# ...
```
```yaml tab="File (YAML)"
providers:
2019-10-29 11:32:05 +00:00
consulCatalog:
2019-11-29 16:16:05 +00:00
prefix: test
2019-10-15 15:34:08 +00:00
# ...
```
```bash tab="CLI"
2019-11-29 16:16:05 +00:00
--providers.consulcatalog.prefix=test
2019-10-15 15:34:08 +00:00
# ...
```
2019-11-29 16:16:05 +00:00
The prefix for Consul Catalog tags defining traefik labels.
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
### `requireConsistent`
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
_Optional, Default=false_
2019-10-15 15:34:08 +00:00
```toml tab="File (TOML)"
2019-10-29 11:32:05 +00:00
[providers.consulCatalog]
2019-10-31 10:56:05 +00:00
requireConsistent = true
2019-10-15 15:34:08 +00:00
# ...
```
```yaml tab="File (YAML)"
providers:
2019-10-29 11:32:05 +00:00
consulCatalog:
2019-10-31 10:56:05 +00:00
requireConsistent: true
2019-10-15 15:34:08 +00:00
# ...
```
```bash tab="CLI"
2019-10-31 10:56:05 +00:00
--providers.consulcatalog.requireConsistent=true
2019-10-15 15:34:08 +00:00
# ...
```
2019-10-31 10:56:05 +00:00
Forces the read to be fully consistent.
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
### `stale`
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
_Optional, Default=false_
2019-10-15 15:34:08 +00:00
```toml tab="File (TOML)"
2019-10-29 11:32:05 +00:00
[providers.consulCatalog]
2019-10-31 10:56:05 +00:00
stale = true
2019-10-15 15:34:08 +00:00
# ...
```
```yaml tab="File (YAML)"
providers:
2019-10-29 11:32:05 +00:00
consulCatalog:
2019-10-31 10:56:05 +00:00
stale: true
2019-10-15 15:34:08 +00:00
# ...
```
```bash tab="CLI"
2019-10-31 10:56:05 +00:00
--providers.consulcatalog.stale=true
2019-10-15 15:34:08 +00:00
# ...
```
2019-10-31 10:56:05 +00:00
Use stale consistency for catalog reads.
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
### `cache`
2019-10-15 15:34:08 +00:00
2019-10-31 10:56:05 +00:00
_Optional, Default=false_
2019-10-15 15:34:08 +00:00
```toml tab="File (TOML)"
2019-10-29 11:32:05 +00:00
[providers.consulCatalog]
2019-10-31 10:56:05 +00:00
cache = true
2019-10-15 15:34:08 +00:00
# ...
```
```yaml tab="File (YAML)"
providers:
2019-10-29 11:32:05 +00:00
consulCatalog:
2019-10-31 10:56:05 +00:00
cache: true
2019-10-15 15:34:08 +00:00
# ...
```
```bash tab="CLI"
2019-10-31 10:56:05 +00:00
--providers.consulcatalog.cache=true
2019-10-15 15:34:08 +00:00
# ...
```
2019-10-31 10:56:05 +00:00
Use local agent caching for catalog reads.
2019-10-29 11:32:05 +00:00
### `endpoint`
2019-11-29 16:16:05 +00:00
Defines the Consul server endpoint.
2019-10-29 11:32:05 +00:00
#### `address`
_Optional, Default="http://127.0.0.1:8500"_
```toml tab="File (TOML)"
[providers.consulCatalog]
[providers.consulCatalog.endpoint]
address = "http://127.0.0.1:8500"
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
address: http://127.0.0.1:8500
# ...
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.address=http://127.0.0.1:8500
# ...
```
Defines the address of the Consul server.
#### `scheme`
_Optional, Default=""_
```toml tab="File (TOML)"
[providers.consulCatalog]
[providers.consulCatalog.endpoint]
scheme = "https"
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
scheme: https
# ...
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.scheme=https
# ...
```
Defines the URI scheme for the Consul server.
#### `datacenter`
_Optional, Default=""_
```toml tab="File (TOML)"
[providers.consulCatalog]
[providers.consulCatalog.endpoint]
datacenter = "test"
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
datacenter: test
# ...
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.datacenter=test
# ...
```
Defines the Data center to use.
If not provided, the default agent data center is used.
#### `token`
_Optional, Default=""_
```toml tab="File (TOML)"
[providers.consulCatalog]
[providers.consulCatalog.endpoint]
token = "test"
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
token: test
# ...
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.token=test
# ...
```
Token is used to provide a per-request ACL token which overrides the agent's default token.
#### `endpointWaitTime`
_Optional, Default=""_
```toml tab="File (TOML)"
[providers.consulCatalog]
[providers.consulCatalog.endpoint]
endpointWaitTime = "15s"
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
endpointWaitTime: 15s
# ...
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.endpointwaittime=15s
# ...
```
WaitTime limits how long a Watch will block.
If not provided, the agent default values will be used
#### `httpAuth`
_Optional_
Used to authenticate http client with HTTP Basic Authentication.
##### `username`
_Optional_
```toml tab="File (TOML)"
[providers.consulCatalog.endpoint.httpAuth]
username = "test"
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
httpAuth:
username: test
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.httpauth.username=test
```
Username to use for HTTP Basic Authentication
##### `password`
_Optional_
```toml tab="File (TOML)"
[providers.consulCatalog.endpoint.httpAuth]
password = "test"
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
httpAuth:
password: test
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.httpauth.password=test
```
Password to use for HTTP Basic Authentication
#### `tls`
_Optional_
Defines TLS options for Consul server endpoint.
##### `ca`
_Optional_
```toml tab="File (TOML)"
[providers.consulCatalog.endpoint.tls]
ca = "path/to/ca.crt"
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
tls:
ca: path/to/ca.crt
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.tls.ca=path/to/ca.crt
```
`ca` is the path to the CA certificate used for Consul communication, defaults to the system bundle if not specified.
##### `caOptional`
_Optional_
```toml tab="File (TOML)"
[providers.consulCatalog.endpoint.tls]
caOptional = true
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
tls:
caOptional: true
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.tls.caoptional=true
```
Policy followed for the secured connection with TLS Client Authentication to Consul.
Requires `tls.ca` to be defined.
- `true`: VerifyClientCertIfGiven
- `false`: RequireAndVerifyClientCert
- if `tls.ca` is undefined NoClientCert
##### `cert`
_Optional_
```toml tab="File (TOML)"
[providers.consulCatalog.endpoint.tls]
cert = "path/to/foo.cert"
key = "path/to/foo.key"
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
tls:
cert: path/to/foo.cert
key: path/to/foo.key
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.tls.cert=path/to/foo.cert
--providers.consulcatalog.endpoint.tls.key=path/to/foo.key
```
`cert` is the path to the public certificate for Consul communication.
If this is set then you need to also set `key.
##### `key`
_Optional_
```toml tab="File (TOML)"
[providers.consulCatalog.endpoint.tls]
cert = "path/to/foo.cert"
key = "path/to/foo.key"
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
tls:
cert: path/to/foo.cert
key: path/to/foo.key
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.tls.cert=path/to/foo.cert
--providers.consulcatalog.endpoint.tls.key=path/to/foo.key
```
`key` is the path to the private key for Consul communication.
If this is set then you need to also set `cert`.
##### `insecureSkipVerify`
_Optional_
```toml tab="File (TOML)"
[providers.consulCatalog.endpoint.tls]
insecureSkipVerify = true
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
endpoint:
tls:
insecureSkipVerify: true
```
```bash tab="CLI"
--providers.consulcatalog.endpoint.tls.insecureskipverify=true
```
If `insecureSkipVerify` is `true`, TLS for the connection to Consul server accepts any certificate presented by the server and any host name in that certificate.
2019-10-31 10:56:05 +00:00
### `exposedByDefault`
_Optional, Default=true_
```toml tab="File (TOML)"
[providers.consulCatalog]
exposedByDefault = false
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
exposedByDefault: false
# ...
```
```bash tab="CLI"
--providers.consulcatalog.exposedByDefault=false
# ...
```
Expose Consul Catalog services by default in Traefik.
2019-11-29 16:16:05 +00:00
If set to false, services that don't have a `traefik.enable=true` tag will be ignored from the resulting routing configuration.
2019-10-31 10:56:05 +00:00
See also [Restrict the Scope of Service Discovery](./overview.md#restrict-the-scope-of-service-discovery).
### `defaultRule`
_Optional, Default=```Host(`{{ normalize .Name }}`)```_
```toml tab="File (TOML)"
[providers.consulCatalog]
defaultRule = "Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
defaultRule: "Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"
# ...
```
```bash tab="CLI"
--providers.consulcatalog.defaultRule="Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"
# ...
```
The default host rule for all services.
2019-11-29 16:16:05 +00:00
For a given service if no routing rule was defined by a tag, it is defined by this defaultRule instead.
2019-10-31 10:56:05 +00:00
It must be a valid [Go template](https://golang.org/pkg/text/template/),
augmented with the [sprig template functions](http://masterminds.github.io/sprig/).
The service name can be accessed as the `Name` identifier,
2019-11-29 16:16:05 +00:00
and the template has access to all the labels (i.e. tags beginning with the `prefix`) defined on this service.
2019-10-31 10:56:05 +00:00
2019-11-29 16:16:05 +00:00
The option can be overridden on an instance basis with the `traefik.http.routers.{name-of-your-choice}.rule` tag.
2019-10-31 10:56:05 +00:00
### `constraints`
_Optional, Default=""_
```toml tab="File (TOML)"
[providers.consulCatalog]
2019-11-29 16:16:05 +00:00
constraints = "Tag(`a.tag.name`)"
2019-10-31 10:56:05 +00:00
# ...
```
```yaml tab="File (YAML)"
providers:
consulCatalog:
2019-11-29 16:16:05 +00:00
constraints: "Tag(`a.tag.name`)"
2019-10-31 10:56:05 +00:00
# ...
```
```bash tab="CLI"
2019-11-29 16:16:05 +00:00
--providers.consulcatalog.constraints="Tag(`a.tag.name`)"
2019-10-31 10:56:05 +00:00
# ...
```
2019-11-29 16:16:05 +00:00
Constraints is an expression that Traefik matches against the service's tags to determine whether to create any route for that service.
That is to say, if none of the service's tags match the expression, no route for that service is created.
If the expression is empty, all detected services are included.
2019-10-31 10:56:05 +00:00
2020-02-13 09:26:04 +00:00
The expression syntax is based on the ```Tag(`tag`)```, and ```TagRegex(`tag`)``` functions,
2019-11-29 16:16:05 +00:00
as well as the usual boolean logic, as shown in examples below.
2019-10-31 10:56:05 +00:00
??? example "Constraints Expression Examples"
```toml
2019-11-29 16:16:05 +00:00
# Includes only services having the tag `a.tag.name=foo`
constraints = "Tag(`a.tag.name=foo`)"
2019-10-31 10:56:05 +00:00
```
```toml
2019-11-29 16:16:05 +00:00
# Excludes services having any tag `a.tag.name=foo`
constraints = "!Tag(`a.tag.name=foo`)"
2019-10-31 10:56:05 +00:00
```
```toml
# With logical AND.
2019-11-29 16:16:05 +00:00
constraints = "Tag(`a.tag.name`) && Tag(`another.tag.name`)"
2019-10-31 10:56:05 +00:00
```
```toml
# With logical OR.
2019-11-29 16:16:05 +00:00
constraints = "Tag(`a.tag.name`) || Tag(`another.tag.name`)"
2019-10-31 10:56:05 +00:00
```
```toml
# With logical AND and OR, with precedence set by parentheses.
2019-11-29 16:16:05 +00:00
constraints = "Tag(`a.tag.name`) && (Tag(`another.tag.name`) || Tag(`yet.another.tag.name`))"
2019-10-31 10:56:05 +00:00
```
```toml
2019-11-29 16:16:05 +00:00
# Includes only services having a tag matching the `a\.tag\.t.+` regular expression.
constraints = "TagRegex(`a\.tag\.t.+`)"
2019-10-31 10:56:05 +00:00
```
See also [Restrict the Scope of Service Discovery](./overview.md#restrict-the-scope-of-service-discovery).