Add Traefik (parallel to ingress-nginx on NodePorts 30082/30445) with LAN/CF/GeoIP middlewares

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-02 12:11:13 +01:00
co-authored by Claude Opus 5.5
parent 411e3bebb0
commit f0513d13a7
+236
View File
@@ -309,6 +309,242 @@ applications:
syncOptions:
- CreateNamespace=true
# Traefik - successor of ingress-nginx (IngressClass "traefik").
# Replacements for the nginx snippets, all as Middlewares in this namespace (extraObjects),
# referenced from Ingresses via traefik.ingress.kubernetes.io/router.middlewares:
# traefik-lan-only LAN + pod network only (the internal *.smokyzone.de UIs)
# traefik-cf-only TCP peer must be a Cloudflare range (git., homeassistant.)
# traefik-geoblock-de DE only (tv.smokyzone.de), plugin traefik-geoblock reading the
# DB-IP Lite country DB from /var/lib/ingress-geoip on the node
# traefik-gitea-* rate limit + HSTS for Gitea
# Real client IP: Cloudflare ranges are trusted for X-Forwarded-For on the entrypoints;
# everyone else's X-Forwarded-* headers are discarded. Allow lists without ipStrategy check
# the TCP peer (RemoteAddr), so they can't be fooled by headers.
# The geoblock plugin is downloaded from plugins.traefik.io at start. If that fails the
# middleware is missing and only routers using it (tv) fail - closed, the rest keeps working.
- name: traefik
enabled: true
source:
repoURL: https://traefik.github.io/charts
chart: traefik
targetRevision: "42.2.0"
helm:
values: |
ingressClass:
enabled: true
isDefaultClass: false
name: traefik
providers:
kubernetesIngress:
# Ingresses in these namespaces may reference the Middlewares above.
crossProviderNamespaces: [media, gitea, homeassistant]
service:
spec:
type: NodePort
ports:
web:
nodePort: 30082
http:
redirections:
entryPoint:
to: websecure
scheme: https
permanent: true
forwardedHeaders:
trustedIPs: &cloudflare ["173.245.48.0/20","103.21.244.0/22","103.22.200.0/22","103.31.4.0/22","141.101.64.0/18","108.162.192.0/18","190.93.240.0/20","188.114.96.0/20","197.234.240.0/22","198.41.128.0/17","162.158.0.0/15","104.16.0.0/13","104.24.0.0/14","172.64.0.0/13","131.0.72.0/22","2400:cb00::/32","2606:4700::/32","2803:f800::/32","2405:b500::/32","2405:8100::/32","2a06:98c0::/29","2c0f:f248::/32"]
websecure:
nodePort: 30445
forwardedHeaders:
trustedIPs: *cloudflare
transport:
respondingTimeouts:
# Default 60s would cut long uploads (git push, HA backups); websockets
# (HA, Jellyfin) and streams are not limited by it anyway.
readTimeout: 0
# hostPorts can't be held by two pods: replace the pod instead of surging.
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 1
accessLog:
enabled: true
format: json
fields:
headers:
defaultMode: drop
names:
User-Agent: keep
X-IPCountry: keep
# Jellyfin clients send api_key in the query string - keep it out of the log.
queryParameters:
defaultMode: drop
experimental:
plugins:
geoblock:
moduleName: github.com/david-garcia-garcia/traefik-geoblock
version: v1.2.1
settings:
useUnsafe: true
deployment:
additionalVolumes:
- name: geoip
hostPath:
path: /var/lib/ingress-geoip
type: DirectoryOrCreate
# DB-IP Lite country DB (CC BY 4.0), MaxMind-compatible. Kept on the node so a DB
# exists even if the internet is down at boot; refreshed at start and weekly.
initContainers:
- name: geoip-init
image: curlimages/curl:8.23.0
securityContext:
runAsUser: 0
runAsNonRoot: false
command: ["sh", "-c"]
args:
- |
D=/geoip
fetch() {
for m in $(date -u +%Y-%m) $(date -u -d "@$(( $(date +%s) - 2592000 ))" +%Y-%m); do
if curl -fsSL --retry 3 --max-time 120 -o $D/.dl.gz "https://download.db-ip.com/free/dbip-country-lite-$m.mmdb.gz" \
&& gunzip -c $D/.dl.gz > $D/.dl.mmdb && [ -s $D/.dl.mmdb ]; then
chmod 644 $D/.dl.mmdb && mv $D/.dl.mmdb $D/GeoLite2-Country.mmdb
rm -f $D/.dl.gz; echo "GeoIP: dbip-country-lite-$m"; return 0
fi
done
rm -f $D/.dl.gz $D/.dl.mmdb; return 1
}
fetch && exit 0
if [ -s $D/GeoLite2-Country.mmdb ]; then echo "GeoIP: download failed, keeping existing DB"; exit 0; fi
echo "GeoIP: no database available"; exit 1
volumeMounts:
- name: geoip
mountPath: /geoip
additionalContainers:
- name: geoip-update
image: curlimages/curl:8.23.0
securityContext:
runAsUser: 0
runAsNonRoot: false
command: ["sh", "-c"]
args:
- |
D=/geoip
while true; do
sleep 604800
for m in $(date -u +%Y-%m) $(date -u -d "@$(( $(date +%s) - 2592000 ))" +%Y-%m); do
if curl -fsSL --retry 3 --max-time 120 -o $D/.dl.gz "https://download.db-ip.com/free/dbip-country-lite-$m.mmdb.gz" \
&& gunzip -c $D/.dl.gz > $D/.dl.mmdb && [ -s $D/.dl.mmdb ]; then
chmod 644 $D/.dl.mmdb && mv $D/.dl.mmdb $D/GeoLite2-Country.mmdb; echo "GeoIP updated: $m"; break
fi
done
rm -f $D/.dl.gz $D/.dl.mmdb
done
resources:
requests: {cpu: 1m, memory: 8Mi}
limits: {memory: 64Mi}
volumeMounts:
- name: geoip
mountPath: /geoip
additionalVolumeMounts:
- name: geoip
mountPath: /geoip
readOnly: true
resources:
requests: {cpu: 50m, memory: 96Mi}
limits: {memory: 512Mi}
extraObjects:
- apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: lan-only
namespace: traefik
spec:
ipAllowList:
# Home network + pods (incl. Tailscale subnet router, 10.1.0.0/16), but NOT
# 192.168.2.218: the router's internet forward to the NodePort arrives SNATed
# as the node's own IP. LAN clients use hostPort 443 with their real IP.
sourceRange: ["192.168.2.0/25","192.168.2.128/26","192.168.2.192/28","192.168.2.208/29","192.168.2.216/31","192.168.2.219/32","192.168.2.220/30","192.168.2.224/27","10.1.0.0/16"]
- apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: cf-only
namespace: traefik
spec:
ipAllowList:
# tv.smokyzone.de (DNS-only) reveals the home IP; the proxied hosts must not be
# reachable directly, bypassing Cloudflare.
sourceRange: ["173.245.48.0/20","103.21.244.0/22","103.22.200.0/22","103.31.4.0/22","141.101.64.0/18","108.162.192.0/18","190.93.240.0/20","188.114.96.0/20","197.234.240.0/22","198.41.128.0/17","162.158.0.0/15","104.16.0.0/13","104.24.0.0/14","172.64.0.0/13","131.0.72.0/22","2400:cb00::/32","2606:4700::/32","2803:f800::/32","2405:b500::/32","2405:8100::/32","2a06:98c0::/29","2c0f:f248::/32"]
- apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: geoblock-de
namespace: traefik
spec:
plugin:
geoblock:
mode: enrichandblock
# TCP peer only: tv is not behind a proxy, headers would be spoofable.
ipHeaders: [remoteAddress]
countryHeader: X-IPCountry
allowedCountries: [DE]
defaultAllow: false
# Also private/unknown IPs get 403 - LAN/Tailscale use jellyfin.smokyzone.de.
allowPrivate: false
banIfError: true
disallowedStatusCode: 403
databaseSources:
default_ip2location:
enabled: false
dbip:
enabled: true
databaseType: mmdb
fieldsPreconfigured: maxmind_country
path: /geoip/GeoLite2-Country.mmdb
logLevel: warn
- apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: gitea-ratelimit
namespace: traefik
spec:
rateLimit:
average: 10
burst: 50
# Behind Cloudflare: rightmost X-Forwarded-For entry = client as seen by CF.
sourceCriterion:
ipStrategy:
depth: 1
- apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: gitea-hsts
namespace: traefik
spec:
headers:
stsSeconds: 31536000
stsIncludeSubdomains: false
destination:
server: https://kubernetes.default.svc
namespace: traefik
syncPolicy:
automated:
prune: true
selfHeal: true
# During the switch from ingress-nginx the NodePorts/hostPorts only become free once
# the old controller is gone.
retry:
limit: 10
backoff:
duration: 20s
factor: 2
maxDuration: 5m
syncOptions:
- CreateNamespace=true
- ServerSideApply=true
# Middlewares (extraObjects) are applied in the same sync as the Traefik CRDs.
- SkipDryRunOnMissingResource=true
# Gitea - Git server for all *-gitops repos (and thus ArgoCD's own source).
# Was created by hand with kubectl; now managed here.
# No chart-managed admin: the bootstrap user gitea_admin was deleted, the user's