This PR adds a better template-ized version of the current traefik.hcl job. This allows new services to be added easier without needing to repeat the same thing over-and-over.
Example Usage
$ cat services.hcl
consul_services = [
{
name = "grafana"
port = 3000
}
]
$ nomad plan -verbose -var-file=services.hcl traefik_template.hcl
$ nomad run -verbose -var-file=services.hcl traefik_template.hcl
Which will result in the following system job on each client node to handle ingress traffic with Traefik, through to a Consul service mesh using Envoy:
So that, at a high-level, this can be achieved:
Dynamically Generated Configuration
To get a better idea of how this config is dynamically generated from the consul_services variable, here are some examples:
Dynamically Generated Static Ingress Port Allocations for Services
This dynamic block in the job definition will configure a port allocation for the service:
Which, for the default value, and example variable file, would result in:
port "grafana" {
static = 3000
to = 3000
}
These allocated ports are the ports that you'll use in your cloud load balancer configurations to handle sending ingress traffic to Nomad using Terraform.
service {
name = "traefik-grafana"
port = "grafana"
connect {
sidecar_service {
proxy {
upstreams {
destination_name = "grafana"
local_bind_port = 3001
}
}
}
}
}
Dynamically Generated Traefik TOML
locals {
dynamic_entry_points = [for i, service in var.consul_services : format(" [entryPoints.%s]\n address = \":%d\"", service.name, service.port)]
traefik_toml = <<EOT
[entryPoints]
${join("\n", local.dynamic_entry_points)}
... removed some content not related to entrypoints for brevity ...
EOT
}
This PR adds a better template-ized version of the current
traefik.hcl
job. This allows new services to be added easier without needing to repeat the same thing over-and-over.Example Usage
Which will result in the following system job on each client node to handle ingress traffic with Traefik, through to a Consul service mesh using Envoy:
So that, at a high-level, this can be achieved:
Dynamically Generated Configuration
To get a better idea of how this config is dynamically generated from the
consul_services
variable, here are some examples:Dynamically Generated Static Ingress Port Allocations for Services
This
dynamic
block in the job definition will configure aport
allocation for the service:Which, for the default value, and example variable file, would result in:
These allocated ports are the ports that you'll use in your cloud load balancer configurations to handle sending ingress traffic to Nomad using Terraform.
Dynamically Generated Consul Service Upstreams
Dynamically Generated Traefik TOML