Skip to main content

Consul Catalog Provider

A Story of Tags, Services & Instances Attach tags to your Consul services and let Traefik automatically discover and route traffic. The Consul Catalog provider watches service registrations in HashiCorp Consul and dynamically updates routing configuration.

Quick Start

1

Enable Consul Catalog Provider

2

Register Service with Tags

3

Access Your Service

Traefik automatically detects the service and creates routes!

How It Works

The Consul Catalog provider:
  1. Polls Consul at regular intervals (or uses watch mode)
  2. Discovers services with tags matching the configured prefix
  3. Extracts routing configuration from service tags
  4. Creates routes dynamically
  5. Updates on changes when services are added/removed

Service Registration Examples

Basic HTTP Service

Service with Middleware

Multiple Routers per Service

Provider Configuration

endpoint

Consul server connection settings.

address

Default: 127.0.0.1:8500

scheme

Optional, Default: "" URI scheme (http or https):

datacenter

Optional, Default: Agent’s datacenter

token

Optional, Default: "" Consul ACL token:
Don’t commit tokens to version control. Use environment variables or secret management.

httpAuth

HTTP Basic Authentication:

tls

TLS configuration for secure connection:

prefix

Default: traefik Tag prefix for Traefik configuration:

refreshInterval

Default: 15s Polling interval:
Ignored when watch: true is enabled.

watch

Optional, Default: false Use Consul watches for real-time updates:

exposedByDefault

Default: true Expose all services by default:

defaultRule

Default: Host(`{{ normalize .Name }}`) Default routing rule template:

constraints

Optional, Default: "" Filter services by tags:

Consistency Mode

Control Consul read consistency:

requireConsistent

Default: false Force fully consistent reads:

stale

Default: false Allow stale reads (faster, scalable):

cache

Default: false Use local agent caching:

Consul Connect

connectAware

Default: false Enable Consul Connect support:

connectByDefault

Default: false Treat all services as Connect-capable:

namespaces (Enterprise)

Optional, Default: "" Watch specific Consul Enterprise namespaces:
Requires Consul Enterprise with namespace support.

strictChecks

Default: ["passing", "warning"] Health check statuses allowed to receive traffic:

Complete Example

Advanced Patterns

Canary Deployments

Multi-Datacenter Setup

Register with datacenter tag:

Service Mesh with Consul Connect

Register Connect-enabled service:

Tag Syntax

All Traefik labels work as Consul tags, replacing . with the prefix:

Troubleshooting

Services Not Discovered

1

Check Consul Connection

2

Verify Service Tags

Ensure tags start with configured prefix.
3

Check exposedByDefault

If false, ensure service has traefik.enable=true tag.
4

Review Constraints

Verify service tags match configured constraints.

Health Checks Failing

ACL Errors

Ensure token has proper permissions:

Best Practices

1

Use Health Checks

Always configure Consul health checks for services.
2

Enable Watch Mode

Use watch: true for real-time updates instead of polling.
3

Set Proper Consistency

Use stale: true for better performance in large deployments.
4

Tag Consistently

Develop a tagging strategy (environment, version, team, etc.).
5

Secure Communication

Use TLS and ACL tokens for Consul connections.

Next Steps

Routing Overview

Learn about routing configuration

Consul Documentation

Official HashiCorp Consul documentation