2022-02-16 09:56:18 -08:00
job "traefik" {
datacenters = ["dc1"]
2022-07-28 15:11:59 -07:00
type = "service"
2022-06-23 09:51:42 -07:00
priority = 100
2022-02-16 09:56:18 -08:00
2022-02-27 14:49:00 -08:00
constraint {
attribute = "${node.class}"
value = "ingress"
}
2022-07-28 15:11:59 -07:00
constraint {
distinct_hosts = true
}
2022-06-23 20:12:30 -07:00
update {
max_parallel = 1
2024-05-28 11:43:46 -07:00
min_healthy_time = "30s"
healthy_deadline = "5m"
2025-02-24 09:22:10 -08:00
auto_revert = true
# Cannot do canary unless I have an unallocated host
# canary = 1
# auto_promote = false
2022-06-23 20:12:30 -07:00
}
2022-02-16 09:56:18 -08:00
group "traefik" {
2024-01-04 13:24:15 -08:00
count = 2
2022-02-16 09:56:18 -08:00
network {
port "web" {
static = 80
}
2022-09-04 20:21:02 -07:00
2022-02-16 09:56:18 -08:00
port "websecure" {
static = 443
}
2022-09-04 20:21:02 -07:00
port "syslog" {
static = 514
}
2023-07-07 16:34:50 -07:00
2023-07-19 09:28:08 -07:00
port "gitssh" {
static = 2222
}
2024-02-13 12:03:03 -08:00
port "metrics" {}
2022-02-16 09:56:18 -08:00
}
2022-07-27 17:30:35 -07:00
ephemeral_disk {
migrate = true
sticky = true
}
2022-02-16 09:56:18 -08:00
task "traefik" {
driver = "docker"
2024-01-23 12:08:47 -08:00
service {
name = "traefik"
provider = "nomad"
port = "web"
check {
type = "http"
path = "/ping"
interval = "10s"
timeout = "2s"
}
tags = [
"traefik.enable=true",
"traefik.http.routers.traefik.entryPoints=websecure",
"traefik.http.routers.traefik.service=api@internal",
]
2023-01-13 15:47:48 -08:00
}
2024-02-13 12:03:03 -08:00
service {
name = "traefik-metrics"
provider = "nomad"
port = "metrics"
tags = [
"prometheus.scrape",
]
}
2022-02-16 09:56:18 -08:00
config {
2024-05-28 11:43:46 -07:00
image = "traefik:3.0"
2022-02-16 09:56:18 -08:00
2024-02-13 12:03:03 -08:00
ports = ["web", "websecure", "syslog", "gitssh", "metrics"]
2022-02-16 09:56:18 -08:00
network_mode = "host"
2022-03-14 15:58:03 -07:00
mount {
type = "bind"
target = "/etc/traefik"
2022-07-26 21:45:06 -07:00
source = "local/config"
2022-03-14 15:58:03 -07:00
}
2022-07-26 21:45:06 -07:00
mount {
type = "bind"
target = "/etc/traefik/usersfile"
source = "secrets/usersfile"
}
2024-01-03 13:56:43 -08:00
mount {
type = "bind"
target = "/etc/traefik/certs"
source = "secrets/certs"
}
2022-07-26 21:45:06 -07:00
}
2024-05-28 12:00:13 -07:00
env = {
TRAEFIK_PROVIDERS_NOMAD_ENDPOINT_TOKEN = "${NOMAD_TOKEN}"
}
identity {
env = true
}
2022-03-14 15:58:03 -07:00
template {
# Avoid conflict with TOML lists [[ ]] and Go templates {{ }}
left_delimiter = "<<"
right_delimiter = ">>"
data = <<EOH
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web]
address = ":80"
[entryPoints.web.http]
[entryPoints.web.http.redirections]
[entryPoints.web.http.redirections.entrypoint]
to = "websecure"
scheme = "https"
[entryPoints.websecure]
address = ":443"
[entryPoints.websecure.http.tls]
[entryPoints.metrics]
2024-02-18 07:47:31 -08:00
address = ":<< env "NOMAD_PORT_metrics" >>"
2022-03-14 15:58:03 -07:00
2022-09-04 12:36:26 -07:00
[entryPoints.syslogtcp]
address = ":514"
[entryPoints.syslogudp]
address = ":514/udp"
2023-07-19 09:28:08 -07:00
[entryPoints.gitssh]
address = ":2222"
2022-03-14 15:58:03 -07:00
[api]
dashboard = true
[ping]
entrypoint = "web"
[metrics]
[metrics.prometheus]
entrypoint = "metrics"
# manualRouting = true
[providers.file]
directory = "/etc/traefik/conf"
watch = true
2023-03-24 08:50:16 -07:00
[providers.nomad]
exposedByDefault = false
2022-11-20 16:24:00 -08:00
defaultRule = "Host(`{{normalize .Name}}.<< with nomadVar "nomad/jobs" >><< .base_hostname >><< end >>`)"
2023-03-24 08:50:16 -07:00
[providers.nomad.endpoint]
2024-05-28 12:00:13 -07:00
address = "unix:///secrets/api.sock"
2022-03-14 15:58:03 -07:00
EOH
2024-01-03 13:56:43 -08:00
destination = "${NOMAD_TASK_DIR}/config/traefik.toml"
2022-07-27 11:12:08 -07:00
}
2022-03-14 15:58:03 -07:00
template {
data = <<EOH
[http]
[http.routers]
[http.routers.nomad]
2022-03-15 11:57:00 -07:00
entryPoints = ["websecure"]
2022-03-14 15:58:03 -07:00
service = "nomad"
2022-11-20 16:24:00 -08:00
rule = "Host(`nomad.{{ with nomadVar "nomad/jobs" }}{{ .base_hostname }}{{ end }}`)"
2024-01-16 14:15:18 -08:00
2024-08-21 20:02:18 -07:00
{{ range nomadVarList "traefik_external" }}{{ with nomadVar .Path }}
[http.routers.{{ .name }}]
2023-03-24 16:32:37 -07:00
entryPoints = ["websecure"]
2024-08-21 20:02:18 -07:00
service = "{{ .name }}"
rule = "Host(`{{ .subdomain }}.{{ with nomadVar "nomad/jobs" }}{{ .base_hostname }}{{ end }}`){{ with .path_prefix.Value }}&&PathPrefix(`{{ . }}`){{ end }}"
{{ $name := .name -}}
{{ with .path_prefix.Value -}}
middlewares = ["{{ $name }}@file"]
{{ end }}
{{- end }}{{ end }}
#[http.middlewares]
# {{ range nomadVarList "traefik_external" }}{{ with nomadVar .Path -}}
# {{ $name := .name -}}
# {{ with .path_prefix.Value -}}
# [http.middlewares.{{ $name }}.stripPrefix]
# prefixes = ["{{ . }}"]
# {{ end }}
# {{- end }}{{ end }}
2022-03-14 15:58:03 -07:00
[http.services]
[http.services.nomad]
[http.services.nomad.loadBalancer]
[[http.services.nomad.loadBalancer.servers]]
2023-03-24 16:32:37 -07:00
url = "http://127.0.0.1:4646"
2024-01-16 14:15:18 -08:00
2024-08-21 20:02:18 -07:00
{{ range nomadVarList "traefik_external" }}{{ with nomadVar .Path }}
[http.services.{{ .name }}]
[http.services.{{ .name }}.loadBalancer]
[[http.services.{{ .name }}.loadBalancer.servers]]
url = "{{ .url }}"
{{- end }}{{ end }}
2022-07-26 21:45:06 -07:00
EOH
2024-01-03 13:56:43 -08:00
destination = "${NOMAD_TASK_DIR}/config/conf/route-hashi.toml"
2022-07-26 21:45:06 -07:00
change_mode = "noop"
2024-01-16 14:15:18 -08:00
splay = "1m"
wait {
min = "10s"
max = "20s"
}
2022-07-26 21:45:06 -07:00
}
2022-09-04 20:21:02 -07:00
template {
data = <<EOH
2022-11-20 16:24:00 -08:00
{{ with nomadService "syslogng" -}}
2022-09-04 20:21:02 -07:00
[tcp.routers]
[tcp.routers.syslogtcp]
entryPoints = ["syslogtcp"]
service = "syslogngtcp"
rule = "HostSNI(`*`)"
[tcp.services]
[tcp.services.syslogngtcp]
[tcp.services.syslogngtcp.loadBalancer]
{{ range . -}}
[[tcp.services.syslogngtcp.loadBalancer.servers]]
address = "{{ .Address }}:{{ .Port }}"
{{ end -}}
2023-03-24 16:32:37 -07:00
{{- end }}
2022-09-04 20:21:02 -07:00
2022-11-20 16:24:00 -08:00
{{ with nomadService "syslogng" -}}
2022-09-04 20:21:02 -07:00
[udp.routers]
[udp.routers.syslogudp]
entryPoints = ["syslogudp"]
service = "syslogngudp"
[udp.services]
[udp.services.syslogngudp]
[udp.services.syslogngudp.loadBalancer]
{{ range . -}}
[[udp.services.syslogngudp.loadBalancer.servers]]
address = "{{ .Address }}:{{ .Port }}"
{{ end -}}
2023-03-24 16:32:37 -07:00
{{- end }}
2022-09-04 20:21:02 -07:00
EOH
2024-01-03 13:56:43 -08:00
destination = "${NOMAD_TASK_DIR}/config/conf/route-syslog-ng.toml"
change_mode = "noop"
2024-01-16 14:15:18 -08:00
splay = "1m"
wait {
min = "10s"
max = "20s"
}
2024-01-03 13:56:43 -08:00
}
template {
data = <<EOF
{{- with nomadVar "secrets/certs/_lego/certificates/__thefij_rocks_crt" }}{{ .contents }}{{ end -}}"
EOF
destination = "${NOMAD_SECRETS_DIR}/certs/_.thefij.rocks.crt"
change_mode = "noop"
}
template {
data = <<EOF
{{- with nomadVar "secrets/certs/_lego/certificates/__thefij_rocks_key" }}{{ .contents }}{{ end -}}"
EOF
destination = "${NOMAD_SECRETS_DIR}/certs/_.thefij.rocks.key"
change_mode = "noop"
}
template {
data = <<EOH
[[tls.certificates]]
certFile = "/etc/traefik/certs/_.thefij.rocks.crt"
keyFile = "/etc/traefik/certs/_.thefij.rocks.key"
EOH
destination = "${NOMAD_TASK_DIR}/config/conf/dynamic-tls.toml"
2022-09-04 20:21:02 -07:00
change_mode = "noop"
}
2022-07-26 21:45:06 -07:00
template {
data = <<EOH
[http.middlewares]
2022-11-20 16:24:00 -08:00
{{ with nomadVar "nomad/jobs/traefik" }}
{{ if .usersfile }}
2022-07-26 21:45:06 -07:00
[http.middlewares.basic-auth.basicAuth]
usersFile = "/etc/traefik/usersfile"
2023-03-24 16:32:37 -07:00
{{- end }}
{{- end }}
2022-07-26 21:45:06 -07:00
EOH
2024-01-03 13:56:43 -08:00
destination = "${NOMAD_TASK_DIR}/config/conf/middlewares.toml"
2022-07-26 21:45:06 -07:00
change_mode = "noop"
}
template {
data = <<EOH
2023-03-24 16:32:37 -07:00
{{ with nomadVar "nomad/jobs/traefik" -}}
2022-11-20 16:24:00 -08:00
{{ .usersfile }}
2023-03-24 16:32:37 -07:00
{{- end }}
2022-03-14 15:58:03 -07:00
EOH
2024-01-03 13:56:43 -08:00
destination = "${NOMAD_SECRETS_DIR}/usersfile"
2022-03-14 15:58:03 -07:00
change_mode = "noop"
2022-02-16 09:56:18 -08:00
}
resources {
2022-07-25 15:51:16 -07:00
cpu = 100
2023-07-31 10:43:03 -07:00
memory = 150
2022-02-16 09:56:18 -08:00
}
}
}
}