Traefik & Rancher

    Attach labels to your services and let Traefik do the rest!

    This provider is specific to Rancher 1.x.

    Rancher 2.x requires Kubernetes and does not have a metadata endpoint of its own for Traefik to query. As such, Rancher 2.x users should utilize the Kubernetes provider directly.

    Configuring Rancher & Deploying / Exposing Services

    Enabling the rancher provider

    File (TOML)

    File (YAML)

    1. providers:
    2. rancher: {}

    CLI

    1. --providers.rancher=true

    Attaching labels to services

    1. labels:
    2. - traefik.http.services.my-service.rule=Host(`example.com`)

    See the dedicated section in .

    Browse the Reference

    If you’re in a hurry, maybe you’d rather go through the configuration reference:

    File (TOML)

    1. # Enable Rancher Provider.
    2. [providers.rancher]
    3. # Expose Rancher services by default in Traefik.
    4. exposedByDefault = true
    5. # Enable watch Rancher changes.
    6. watch = true
    7. # Filter services with unhealthy states and inactive states.
    8. enableServiceHealthFilter = true
    9. # Defines the polling interval (in seconds).
    10. refreshSeconds = 15
    11. # Poll the Rancher metadata service for changes every `rancher.refreshSeconds`, which is less accurate
    12. intervalPoll = false
    13. # Prefix used for accessing the Rancher metadata service
    14. prefix = "/latest"

    File (YAML)

    1. # Enable Rancher Provider.
    2. providers:
    3. rancher:
    4. # Expose Rancher services by default in Traefik.
    5. exposedByDefault: true
    6. # Enable watch Rancher changes.
    7. watch: true
    8. # Filter services with unhealthy states and inactive states.
    9. # Defines the polling interval (in seconds).
    10. refreshSeconds: 15
    11. # Poll the Rancher metadata service for changes every `rancher.refreshSeconds`, which is less accurate
    12. intervalPoll: false
    13. prefix: /latest

    CLI

    1. # Enable Rancher Provider.
    2. --providers.rancher=true
    3. # Expose Rancher services by default in Traefik.
    4. --providers.rancher.exposedByDefault=true
    5. # Enable watch Rancher changes.
    6. --providers.rancher.watch=true
    7. # Filter services with unhealthy states and inactive states.
    8. --providers.rancher.enableServiceHealthFilter=true
    9. # Defines the polling interval (in seconds).
    10. --providers.rancher.refreshSeconds=15
    11. # Poll the Rancher metadata service for changes every `rancher.refreshSeconds`, which is less accurate
    12. --providers.rancher.intervalPoll=false
    13. # Prefix used for accessing the Rancher metadata service
    14. --providers.rancher.prefix=/latest

    Optional, Default=true

    File (TOML)

    1. [providers.rancher]
    2. exposedByDefault = false
    3. # ...
    1. providers:
    2. rancher:
    3. exposedByDefault: false
    4. # ...

    CLI

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

    Expose Rancher services by default in Traefik. If set to false, services that don’t have a traefik.enable=true label will be ignored from the resulting routing configuration.

    See also Restrict the Scope of Service Discovery.

    defaultRule

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

    File (TOML)

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

    File (YAML)

    CLI

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

    The default host rule for all services.

    For a given container if no routing rule was defined by a label, it is defined by this defaultRule instead. It must be a valid Go template, augmented with the . The service name can be accessed as the Name identifier, and the template has access to all the labels defined on this container.

    This option can be overridden on a container basis with the traefik.http.routers.Router1.rule label.

    Optional, Default=true

    File (TOML)

    1. [providers.rancher]
    2. enableServiceHealthFilter = false
    3. # ...

    File (YAML)

    1. rancher:
    2. enableServiceHealthFilter: false
    3. # ...

    CLI

    1. --providers.rancher.enableServiceHealthFilter=false

    Filter services with unhealthy states and inactive states.

    refreshSeconds

    Optional, Default=15

    File (TOML)

    1. [providers.rancher]
    2. refreshSeconds = 30
    3. # ...

    File (YAML)

    1. providers:
    2. rancher:
    3. refreshSeconds: 30
    4. # ...
    1. --providers.rancher.refreshSeconds=30
    2. # ...

    Defines the polling interval (in seconds).

    Optional, Default=false

    File (TOML)

    1. [providers.rancher]
    2. intervalPoll = true
    3. # ...

    File (YAML)

    1. providers:
    2. rancher:
    3. intervalPoll: true
    4. # ...

    CLI

    1. --providers.rancher.intervalPoll=true
    2. # ...

    Poll the Rancher metadata service for changes every rancher.refreshSeconds, which is less accurate than the default long polling technique which will provide near instantaneous updates to Traefik.

    prefix

    Optional, Default=/latest

    File (TOML)

    File (YAML)

    1. providers:
    2. rancher:
    3. prefix: "/test"
    4. # ...

    CLI

    1. --providers.rancher.prefix=/test
    2. # ...

    Prefix used for accessing the Rancher metadata service

    Optional, Default=””

    File (TOML)

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

    File (YAML)

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

    CLI

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

    Constraints is an expression that Traefik matches against the container’s labels to determine whether to create any route for that container. That is to say, if none of the container’s labels match the expression, no route for the container is created. If the expression is empty, all detected containers are included.

    The expression syntax is based on the Label("key", "value"), and LabelRegex("key", "value") functions, as well as the usual boolean logic, as shown in examples below.

    Constraints Expression Examples

    1. # Includes only containers having a label with key `a.label.name` and value `foo`
    2. constraints = "Label(`a.label.name`, `foo`)"
    1. # Excludes containers 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. constraints = "Label(`a.label.name`, `valueA`) && (Label(`another.label.name`, `valueB`) || Label(`yet.another.label.name`, `valueC`))"