Using Traefik with Consul
Consul Key/Value Store and Service Catalog
- Consul has two functions built in to it: a Key/Value store and a Service Catalog
- The Key/Value store is useful for defining variables to be shared in the cluster.
- The Service Catalog is useful for integration with tools like Traefik as a service discovery tool to dynamically define hosts.
- The Consul Service Catalog is used as a service discovery tool.
- The Service Catalog works byt defining a service by name, port, and healthcheck.
- Once the service has been registered, consul will search the host where the consul agent is running for the port and healthcheck.
- The service will be listed in the service catalog: consul catalog services
- Curl can be used to list the services
- The power of the Service Catalog is that it includes a built-in DNS server for all the registered services
Bootstrapping the Contents of a new Consul cluster
Storing Traefik configuration in Consul
- Traefik defines an entrypoint, a frontend, and a backend.
- The entrypoint is a listener, think about it as an http or https point where traffic enters Traefik.
- The entrypoint connects to a frontend. A frontend is a rule for connecting the incoming pipe to the backend outgoing pipe.
- Consul can be used to store the configuration for Traefik so that a static on-disk config file is not needed.
- The frontend is a series of rules which determine how incoming traffic will flow from an entrypoint to the backend.
- The rules used by Traefik are called matchers
- Naturally a hostname request is the most common matching rule
- Rules can be based on the HTTP request method:
- Regular expressions are supported in the rule so long as a named variable is used and the regex is contained in curly brackets:
- Multiple rules can be combined by separating them with a semicolon (;) :
Configure docker container to register itself with the Consul Service Catalog on startup