feat: route wildcard domains through traefik on k3s

Traefik matches hosts exactly, so an app serving a wildcard domain under the `traefik` ingress class had a valid certificate but silently 404d on every request. Wildcard domains now render as a `HostRegexp` rule that matches a single label, the same semantics as a Kubernetes wildcard host, so both ingress classes behave the same. Those routes carry an explicit low priority so an exact domain on any app still wins over another app's wildcard, mirroring ingress-nginx.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-08-08 19:15:10 -04:00
1 parent 6c823e3b8a
commit bb7335f88e
7 files changed
+488 -5

No files matched your search

@@ -16,6 +16,20 @@
{{- end }}
{{- end }}
{{/*
traefik.host.match renders a domain as a Traefik router rule. Traefik v2 resolves HostRegexp
through gorilla/mux, where the pattern is a {name:regexp} template and every literal segment is
quoted, so a wildcard label is spelled out as a named group rather than a raw regexp. The group
matches a single label, mirroring both DNS and Kubernetes Ingress wildcard hosts.
*/}}
{{- define "traefik.host.match" -}}
{{- if hasPrefix "*." . -}}
HostRegexp(`{subdomain:[^.]+}.{{ trimPrefix "*." . }}`)
{{- else -}}
Host(`{{ . }}`)
{{- end -}}
{{- end -}}
{{- define "primary.port" -}}
{{- $found := dict -}}
{{- range $idx, $port_map := . -}}
@@ -39,7 +39,10 @@ spec:
routes:
{{- range $ddx, $domain := $config.web.domains }}
- kind: Rule
match: Host(`{{ $domain.name }}`)
match: {{ include "traefik.host.match" $domain.name }}
{{- if hasPrefix "*." $domain.name }}
priority: 1
{{- end }}
middlewares:
- name: {{ $.Values.global.app_name}}-{{ $processName }}-compression
namespace: {{ $.Values.global.namespace }}