From 81c789cc87d8db8b6934fe82b6768514476b5df5 Mon Sep 17 00:00:00 2001 From: Nils Stinnesbeck Date: Wed, 18 Nov 2026 13:18:48 +0100 Subject: [PATCH] k8s: Traefik IngressRoute instead of an Ingress Optional (off by default): IngressRoute for the UI with TLS (resolver or Secret), a security-headers Middleware and an HTTP-to-HTTPS redirect. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw --- k8s/README.md | 4 +- k8s/base/ingress.yaml | 30 --------------- k8s/base/ingressroute.yaml | 75 +++++++++++++++++++++++++++++++++++++ k8s/base/kustomization.yaml | 4 +- k8s/base/service-http.yaml | 2 +- 5 files changed, 80 insertions(+), 35 deletions(-) delete mode 100644 k8s/base/ingress.yaml create mode 100644 k8s/base/ingressroute.yaml diff --git a/k8s/README.md b/k8s/README.md index 4322d1b..8395b1f 100644 --- a/k8s/README.md +++ b/k8s/README.md @@ -6,7 +6,7 @@ DHT and relays for nodes behind a NAT. It also works behind your home router. ``` k8s/base/ namespace, StatefulSet (+1 Gi volume), Services, config -k8s/base/ingress.yaml optional: the web UI on a public name (off by default) +k8s/base/ingressroute.yaml optional: the web UI on a public name, a Traefik IngressRoute (off by default) k8s/overlays/nodeport/ variant for a cluster without a load balancer ``` @@ -83,7 +83,7 @@ so: `kubectl -n allmende exec allmende-0 -- cat /data/admin.token` - **The web UI** is not published by default. For a look at it: `kubectl -n allmende port-forward svc/allmende-http 8080:8080`. To publish - it, enable `ingress.yaml` in `base/kustomization.yaml` (read its note first: + it, enable `ingressroute.yaml` in `base/kustomization.yaml` (read its note first: the same port serves the owner API). - **Regions.** A bootstrap node follows none. To make it also keep listings, open the UI through the port-forward, sign in and choose regions. diff --git a/k8s/base/ingress.yaml b/k8s/base/ingress.yaml deleted file mode 100644 index f4626c8..0000000 --- a/k8s/base/ingress.yaml +++ /dev/null @@ -1,30 +0,0 @@ -# Optional: the web UI on a public name, so people can search without running -# their own node. Not part of the kustomization until you enable it there. -# -# The same port serves the owner API. It is protected by the admin token -# (which stays on the volume, /data/admin.token), but put TLS in front of it -# and consider limiting /api/v1/ to your own address ranges if you do not need -# the owner screens from outside. -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: allmende - annotations: - # cert-manager.io/cluster-issuer: letsencrypt - nginx.ingress.kubernetes.io/proxy-read-timeout: "60" -spec: - # ingressClassName: nginx - tls: - - hosts: [allmende.example.org] - secretName: allmende-tls - rules: - - host: allmende.example.org - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: allmende-http - port: - name: http diff --git a/k8s/base/ingressroute.yaml b/k8s/base/ingressroute.yaml new file mode 100644 index 0000000..31ff9ff --- /dev/null +++ b/k8s/base/ingressroute.yaml @@ -0,0 +1,75 @@ +# Optional: the web UI on a public name, through Traefik, so people can search +# without running their own node. Not part of the kustomization until you +# enable it there. +# +# There is no separate web image: the UI is built into the allmende binary, so +# the one image (see kustomization.yaml) serves it on port 8080. +# +# The same port serves the owner API. It is protected by the admin token (which +# stays on the volume, /data/admin.token), but TLS is a must, and you may want +# to limit who can reach /api/v1/ beyond reading (see the Middleware below). +# +# The libp2p port (4001) does not go through Traefik: it is not HTTP, and +# service-p2p.yaml already exposes it. +# +# traefik.io/v1alpha1 is the group of Traefik v3 (and v2.10+); for older v2 +# installs use traefik.containo.us/v1alpha1. +apiVersion: traefik.io/v1alpha1 +kind: IngressRoute +metadata: + name: allmende +spec: + entryPoints: + - websecure + routes: + - kind: Rule + match: Host(`allmende.example.org`) + services: + - name: allmende-http + port: http + # middlewares: + # - name: allmende-security-headers + tls: + # Certificates through a resolver configured in Traefik (ACME)... + certResolver: letsencrypt + # ...or from a Secret, e.g. issued by cert-manager: + # secretName: allmende-tls +--- +# Optional, referenced above once you uncomment it: security headers for the UI. +apiVersion: traefik.io/v1alpha1 +kind: Middleware +metadata: + name: allmende-security-headers +spec: + headers: + stsSeconds: 31536000 + stsIncludeSubdomains: true + contentTypeNosniff: true + frameDeny: true + referrerPolicy: no-referrer +--- +# Optional: serve plain HTTP only as a redirect to HTTPS. +apiVersion: traefik.io/v1alpha1 +kind: IngressRoute +metadata: + name: allmende-http-redirect +spec: + entryPoints: + - web + routes: + - kind: Rule + match: Host(`allmende.example.org`) + middlewares: + - name: allmende-redirect-https + services: + - name: noop@internal + kind: TraefikService +--- +apiVersion: traefik.io/v1alpha1 +kind: Middleware +metadata: + name: allmende-redirect-https +spec: + redirectScheme: + scheme: https + permanent: true diff --git a/k8s/base/kustomization.yaml b/k8s/base/kustomization.yaml index 353cfd8..351f0d6 100644 --- a/k8s/base/kustomization.yaml +++ b/k8s/base/kustomization.yaml @@ -14,8 +14,8 @@ resources: - statefulset.yaml - service-p2p.yaml - service-http.yaml - # Optional: the web UI on a public name. Read the note in ingress.yaml first. - # - ingress.yaml + # Optional: the web UI on a public name. Traefik IngressRoute; read the note in ingressroute.yaml first. + # - ingressroute.yaml configMapGenerator: - name: allmende-config diff --git a/k8s/base/service-http.yaml b/k8s/base/service-http.yaml index a656e81..0c2e2a5 100644 --- a/k8s/base/service-http.yaml +++ b/k8s/base/service-http.yaml @@ -1,6 +1,6 @@ # The web UI and API, inside the cluster only. Reach it with # kubectl -n allmende port-forward svc/allmende-http 8080:8080 -# or publish it through ingress.yaml. +# or publish it through ingressroute.yaml (Traefik). apiVersion: v1 kind: Service metadata: