Traefik & Marathon

Traefik can be configured to use Marathon as a provider.

For additional information, refer to Marathon user guide.

Configuration Examples

Configuring Marathon & Deploying / Exposing Applications

Enabling the Marathon provider

File (YAML)

  1. providers:
  2. marathon: {}

File (TOML)

  1. [providers.marathon]

CLI

  1. --providers.marathon=true

Attaching labels to Marathon applications

  1. {
  2. "id": "/whoami",
  3. "container": {
  4. "type": "DOCKER",
  5. "docker": {
  6. "image": "traefik/whoami",
  7. "network": "BRIDGE",
  8. "portMappings": [
  9. {
  10. "containerPort": 80,
  11. "hostPort": 0,
  12. "protocol": "tcp"
  13. }
  14. ]
  15. }
  16. },
  17. "labels": {
  18. "traefik.http.Routers.app.Rule": "PathPrefix(`/app`)"
  19. }
  20. }

Routing Configuration

See the dedicated section in routing.

Provider Configuration

basic

Optional

Enables Marathon basic authentication.

File (YAML)

  1. providers:
  2. marathon:
  3. basic:
  4. httpBasicAuthUser: foo
  5. httpBasicPassword: bar

File (TOML)

  1. [providers.marathon.basic]
  2. httpBasicAuthUser = "foo"
  3. httpBasicPassword = "bar"

CLI

  1. --providers.marathon.basic.httpbasicauthuser=foo
  2. --providers.marathon.basic.httpbasicpassword=bar

dcosToken

Optional

Datacenter Operating System (DCOS) Token for DCOS environment.

If set, it overrides the Authorization header.

File (YAML)

  1. providers:
  2. marathon:
  3. dcosToken: "xxxxxx"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. dcosToken = "xxxxxx"
  3. # ...

CLI

  1. --providers.marathon.dcosToken=xxxxxx

defaultRule

Optional, Default=Host(`{{ normalize .Name }}`)

The default host rule for all services.

For a given application, if no routing rule was defined by a label, it is defined by this defaultRule instead.

It must be a valid Go template, and can include sprig template functions.

The app ID can be accessed with the Name identifier, and the template has access to all the labels defined on this Marathon application.

File (YAML)

  1. providers:
  2. marathon:
  3. defaultRule: "Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. defaultRule = "Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)"
  3. # ...

CLI

  1. --providers.marathon.defaultRule=Host(`{{ .Name }}.{{ index .Labels \"customLabel\"}}`)
  2. # ...

dialerTimeout

Optional, Default=5s

Amount of time the Marathon provider should wait before timing out, when trying to open a TCP connection to a Marathon master.

The value of dialerTimeout should be provided in seconds or as a valid duration format, see time.ParseDuration.

File (YAML)

  1. providers:
  2. marathon:
  3. dialerTimeout: "10s"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. dialerTimeout = "10s"
  3. # ...

CLI

  1. --providers.marathon.dialerTimeout=10s

endpoint

Optional, Default=http://127.0.0.1:8080

Marathon server endpoint.

You can optionally specify multiple endpoints.

File (YAML)

  1. providers:
  2. marathon:
  3. endpoint: "http://10.241.1.71:8080,10.241.1.72:8080,10.241.1.73:8080"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. endpoint = "http://10.241.1.71:8080,10.241.1.72:8080,10.241.1.73:8080"
  3. # ...

CLI

  1. --providers.marathon.endpoint=http://10.241.1.71:8080,10.241.1.72:8080,10.241.1.73:8080

exposedByDefault

Optional, Default=true

Exposes Marathon applications by default through Traefik.

If set to false, applications that do not have a traefik.enable=true label are ignored from the resulting routing configuration.

For additional information, refer to Restrict the Scope of Service Discovery.

File (YAML)

  1. providers:
  2. marathon:
  3. exposedByDefault: false
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. exposedByDefault = false
  3. # ...

CLI

  1. --providers.marathon.exposedByDefault=false
  2. # ...

constraints

Optional, Default=””

The constraints option can be set to an expression that Traefik matches against the application labels to determine whether to create any route for that application. If none of the application labels match the expression, no route for that application is created. In addition, the expression is also matched against the application constraints, such as described in Marathon constraints. If the expression is empty, all detected applications are included.

The expression syntax is based on the Label("key", "value"), and LabelRegex("key", "value") functions, as well as the usual boolean logic. In addition, to match against Marathon constraints, the function MarathonConstraint("field:operator:value") can be used, where the field, operator, and value parts are concatenated in a single string using the : separator.

Constraints Expression Examples

  1. # Includes only applications having a label with key `a.label.name` and value `foo`
  2. constraints = "Label(`a.label.name`, `foo`)"
  1. # Excludes applications having any label with key `a.label.name` and value `foo`
  2. constraints = "!Label(`a.label.name`, `value`)"
  1. # With logical AND.
  2. constraints = "Label(`a.label.name`, `valueA`) && Label(`another.label.name`, `valueB`)"
  1. # With logical OR.
  2. constraints = "Label(`a.label.name`, `valueA`) || Label(`another.label.name`, `valueB`)"
  1. # With logical AND and OR, with precedence set by parentheses.
  2. constraints = "Label(`a.label.name`, `valueA`) && (Label(`another.label.name`, `valueB`) || Label(`yet.another.label.name`, `valueC`))"
  1. # Includes only applications having a label with key `a.label.name` and a value matching the `a.+` regular expression.
  2. constraints = "LabelRegex(`a.label.name`, `a.+`)"
  1. # Includes only applications having a Marathon constraint with field `A`, operator `B`, and value `C`.
  2. constraints = "MarathonConstraint(`A:B:C`)"
  1. # Uses both Marathon constraint and application label with logical operator.
  2. constraints = "MarathonConstraint(`A:B:C`) && Label(`a.label.name`, `value`)"

For additional information, refer to Restrict the Scope of Service Discovery.

File (YAML)

  1. providers:
  2. marathon:
  3. constraints: "Label(`a.label.name`,`foo`)"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. constraints = "Label(`a.label.name`,`foo`)"
  3. # ...

CLI

  1. --providers.marathon.constraints=Label(`a.label.name`,`foo`)
  2. # ...

forceTaskHostname

Optional, Default=false

By default, the task IP address (as returned by the Marathon API) is used as backend server if an IP-per-task configuration can be found; otherwise, the name of the host running the task is used. The latter behavior can be enforced by setting this option to true.

File (YAML)

  1. providers:
  2. marathon:
  3. forceTaskHostname: true
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. forceTaskHostname = true
  3. # ...

CLI

  1. --providers.marathon.forceTaskHostname=true
  2. # ...

keepAlive

Optional, Default=10s

Set the TCP Keep Alive duration for the Marathon HTTP Client. The value of keepAlive should be provided in seconds or as a valid duration format, see time.ParseDuration.

File (YAML)

  1. providers:
  2. marathon:
  3. keepAlive: "30s"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. keepAlive = "30s"
  3. # ...

CLI

  1. --providers.marathon.keepAlive=30s
  2. # ...

respectReadinessChecks

Optional, Default=false

Applications may define readiness checks which are probed by Marathon during deployments periodically, and these check results are exposed via the API. Enabling respectReadinessChecks causes Traefik to filter out tasks whose readiness checks have not succeeded. Note that the checks are only valid during deployments.

See the Marathon guide for details.

File (YAML)

  1. providers:
  2. marathon:
  3. respectReadinessChecks: true
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. respectReadinessChecks = true
  3. # ...

CLI

  1. --providers.marathon.respectReadinessChecks=true
  2. # ...

responseHeaderTimeout

Optional, Default=60s

Amount of time the Marathon provider should wait before timing out when waiting for the first response header from a Marathon master.

The value of responseHeaderTimeout should be provided in seconds or as a valid duration format, see time.ParseDuration.

File (YAML)

  1. providers:
  2. marathon:
  3. responseHeaderTimeout: "66s"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. responseHeaderTimeout = "66s"
  3. # ...

CLI

  1. --providers.marathon.responseHeaderTimeout=66s
  2. # ...

tls

Optional

tls.ca

Certificate Authority used for the secure connection to Marathon.

File (YAML)

  1. providers:
  2. marathon:
  3. tls:
  4. ca: path/to/ca.crt

File (TOML)

  1. [providers.marathon.tls]
  2. ca = "path/to/ca.crt"

CLI

  1. --providers.marathon.tls.ca=path/to/ca.crt

tls.caOptional

The value of tls.caOptional defines which policy should be used for the secure connection with TLS Client Authentication to Marathon.

If tls.ca is undefined, this option will be ignored, and no client certificate will be requested during the handshake. Any provided certificate will thus never be verified.

When this option is set to true, a client certificate is requested during the handshake but is not required. If a certificate is sent, it is required to be valid.

When this option is set to false, a client certificate is requested during the handshake, and at least one valid certificate should be sent by the client.

File (YAML)

  1. providers:
  2. marathon:
  3. tls:
  4. caOptional: true

File (TOML)

  1. [providers.marathon.tls]
  2. caOptional = true

CLI

  1. --providers.marathon.tls.caOptional=true

tls.cert

Public certificate used for the secure connection to Marathon.

File (YAML)

  1. providers:
  2. marathon:
  3. tls:
  4. cert: path/to/foo.cert
  5. key: path/to/foo.key

File (TOML)

  1. [providers.marathon.tls]
  2. cert = "path/to/foo.cert"
  3. key = "path/to/foo.key"

CLI

  1. --providers.marathon.tls.cert=path/to/foo.cert
  2. --providers.marathon.tls.key=path/to/foo.key

tls.key

Private certificate used for the secure connection to Marathon.

File (YAML)

  1. providers:
  2. marathon:
  3. tls:
  4. cert: path/to/foo.cert
  5. key: path/to/foo.key

File (TOML)

  1. [providers.marathon.tls]
  2. cert = "path/to/foo.cert"
  3. key = "path/to/foo.key"

CLI

  1. --providers.marathon.tls.cert=path/to/foo.cert
  2. --providers.marathon.tls.key=path/to/foo.key

tls.insecureSkipVerify

If insecureSkipVerify is true, the TLS connection to Marathon accepts any certificate presented by the server regardless of the hostnames it covers.

File (YAML)

  1. providers:
  2. marathon:
  3. tls:
  4. insecureSkipVerify: true

File (TOML)

  1. [providers.marathon.tls]
  2. insecureSkipVerify = true

CLI

  1. --providers.marathon.tls.insecureSkipVerify=true

tlsHandshakeTimeout

Optional, Default=5s

Amount of time the Marathon provider should wait before timing out, when waiting for the TLS handshake to complete.

The value of tlsHandshakeTimeout should be provided in seconds or as a valid duration format, see time.ParseDuration.

File (YAML)

  1. providers:
  2. marathon:
  3. responseHeaderTimeout: "10s"
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. responseHeaderTimeout = "10s"
  3. # ...

CLI

  1. --providers.marathon.responseHeaderTimeout=10s
  2. # ...

trace

Optional, Default=false

Displays additional provider logs when available.

File (YAML)

  1. providers:
  2. marathon:
  3. trace: true
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. trace = true
  3. # ...

CLI

  1. --providers.marathon.trace=true
  2. # ...

watch

Optional, Default=true

When set to true, watches for Marathon changes.

File (YAML)

  1. providers:
  2. marathon:
  3. watch: false
  4. # ...

File (TOML)

  1. [providers.marathon]
  2. watch = false
  3. # ...

CLI

  1. --providers.marathon.watch=false
  2. # ...