create custom nixos module for k8s ingress

This commit is contained in:
Pim Kunis 2024-04-14 23:11:19 +02:00
parent 4b01eeadbb
commit 4ded27d82e
15 changed files with 193 additions and 483 deletions

View file

@ -21,5 +21,6 @@
./metallb.nix ./metallb.nix
./cert-manager.nix ./cert-manager.nix
./minecraft.nix ./minecraft.nix
./custom/ingress.nix
]; ];
} }

View file

@ -0,0 +1,68 @@
{ lib, config, ... }:
let
ingressOpts = { name, ... }: {
options = {
host = lib.mkOption {
type = lib.types.str;
};
entrypoint = lib.mkOption {
type = lib.types.str;
default = "websecure";
};
service = {
name = lib.mkOption {
type = lib.types.str;
};
portName = lib.mkOption {
type = lib.types.str;
};
};
};
};
in
{
options = {
lab.ingresses = lib.mkOption {
type = with lib.types; attrsOf (submodule ingressOpts);
default = { };
};
};
config = {
kubernetes.resources.ingresses = builtins.mapAttrs
(name: ingress: {
metadata.annotations = {
"cert-manager.io/cluster-issuer" = "letsencrypt";
"traefik.ingress.kubernetes.io/router.entrypoints" = ingress.entrypoint;
};
spec = {
ingressClassName = "traefik";
rules = [{
host = ingress.host;
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = ingress.service.name;
port.name = ingress.service.portName;
};
}];
}];
tls = [{
secretName = "${name}-tls";
hosts = [ ingress.host ];
}];
};
})
config.lab.ingresses;
};
}

View file

@ -22,32 +22,14 @@
targetPort = "web"; targetPort = "web";
}; };
}; };
};
ingresses.cyberchef = { lab.ingresses.cyberchef = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "cyberchef.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "cyberchef";
portName = "web";
rules = [{
host = "cyberchef.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "cyberchef";
port.name = "web";
};
}];
}];
tls = [{
secretName = "cyberchef-tls";
hosts = [ "cyberchef.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -9,32 +9,14 @@
targetPort = 80; targetPort = 80;
}; };
}; };
};
ingresses.esrom = { lab.ingresses.esrom = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "esrom.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "esrom";
portName = "web";
rules = [{
host = "esrom.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "esrom";
port.name = "web";
};
}];
}];
tls = [{
secretName = "esrom-tls";
hosts = [ "esrom.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -196,32 +196,14 @@
}; };
}; };
}; };
};
ingresses.forgejo = { lab.ingresses.forgejo = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "git.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "forgejo-web";
portName = "web";
rules = [{
host = "git.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "forgejo-web";
port.name = "web";
};
}];
}];
tls = [{
secretName = "forgejo-tls";
hosts = [ "git.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -73,32 +73,14 @@
targetPort = "web"; targetPort = "web";
}; };
}; };
};
ingresses.freshrss = { lab.ingresses.freshrss = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "rss.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "freshrss";
portName = "web";
rules = [{
host = "rss.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "freshrss";
port.name = "web";
};
}];
}];
tls = [{
secretName = "freshrss-tls";
hosts = [ "rss.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -98,32 +98,14 @@
targetPort = "web"; targetPort = "web";
}; };
}; };
};
ingresses.hedgedoc = { lab.ingresses.hedgedoc = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "md.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "hedgedoc";
portName = "web";
rules = [{
host = "md.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "hedgedoc";
port.name = "web";
};
}];
}];
tls = [{
secretName = "hedgedoc-tls";
hosts = [ "md.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -44,35 +44,15 @@
}]; }];
}; };
}; };
};
ingresses.inbucket = { lab.ingresses.inbucket = {
metadata.annotations = { host = "inbucket.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "inbucket-web";
portName = "web";
rules = [{
host = "inbucket.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "inbucket-web";
port.name = "web";
};
}];
}];
tls = [{
secretName = "inbucket-tls";
hosts = [ "inbucket.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -114,32 +114,14 @@
}; };
}; };
}; };
};
ingresses.kitchenowl = { lab.ingresses.kitchenowl = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "boodschappen.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "kitchenowl-web";
portName = "web";
rules = [{
host = "boodschappen.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "kitchenowl-web";
port.name = "web";
};
}];
}];
tls = [{
secretName = "kitchenowl-tls";
hosts = [ "boodschappen.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -581,212 +581,75 @@
}; };
}; };
}; };
};
ingresses = { lab.ingresses = {
jellyfin = { jellyfin = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "media.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "jellyfin";
portName = "web";
rules = [{
host = "media.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "jellyfin";
port.name = "web";
};
}];
}];
tls = [{
secretName = "jellyfin-tls";
hosts = [ "media.kun.is" ];
}];
};
}; };
};
transmission = { transmission = {
metadata.annotations = { host = "transmission.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "transmission-web";
portName = "web";
rules = [{
host = "transmission.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "transmission-web";
port.name = "web";
};
}];
}];
tls = [{
secretName = "transmission-tls";
hosts = [ "transmission.kun.is" ];
}];
};
}; };
};
jellyseerr = { jellyseerr = {
metadata.annotations = { host = "jellyseerr.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "jellyseerr";
portName = "web";
rules = [{
host = "jellyseerr.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "jellyseerr";
port.name = "web";
};
}];
}];
tls = [{
secretName = "jellyseerr-tls";
hosts = [ "jellyseerr.kun.is" ];
}];
};
}; };
};
radarr = { radarr = {
metadata.annotations = { host = "radarr.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "radarr";
portName = "web";
rules = [{
host = "radarr.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "radarr";
port.name = "web";
};
}];
}];
tls = [{
secretName = "radarr-tls";
hosts = [ "radarr.kun.is" ];
}];
};
}; };
};
prowlarr = { prowlarr = {
metadata.annotations = { host = "prowlarr.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "prowlarr";
portName = "web";
rules = [{
host = "prowlarr.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "prowlarr";
port.name = "web";
};
}];
}];
tls = [{
secretName = "prowlarr-tls";
hosts = [ "prowlarr.kun.is" ];
}];
};
}; };
};
sonarr = { sonarr = {
metadata.annotations = { host = "sonarr.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "sonarr";
portName = "web";
rules = [{
host = "sonarr.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "sonarr";
port.name = "web";
};
}];
}];
tls = [{
secretName = "sonarr-tls";
hosts = [ "sonarr.kun.is" ];
}];
};
}; };
};
bazarr = { bazarr = {
metadata.annotations = { host = "bazarr.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = {
ingressClassName = "traefik";
rules = [{ service = {
host = "bazarr.kun.is"; name = "bazarr";
portName = "web";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "bazarr";
port.name = "web";
};
}];
}];
tls = [{
secretName = "bazarr-tls";
hosts = [ "bazarr.kun.is" ];
}];
};
}; };
}; };
}; };

View file

@ -65,32 +65,14 @@
targetPort = "web"; targetPort = "web";
}; };
}; };
};
ingresses.nextcloud = { lab.ingresses.nextcloud = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "cloud.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "nextcloud";
portName = "web";
rules = [{
host = "cloud.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "nextcloud";
port.name = "web";
};
}];
}];
tls = [{
secretName = "nextcloud-tls";
hosts = [ "cloud.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -168,32 +168,14 @@
}; };
}; };
}; };
};
ingresses.paperless-ngx = { lab.ingresses.paperless-ngx = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "paperless.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "paperless-ngx-web";
portName = "web";
rules = [{
host = "paperless.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "paperless-ngx-web";
port.name = "web";
};
}];
}];
tls = [{
secretName = "paperless-ngx-tls";
hosts = [ "paperless.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -116,35 +116,15 @@
}; };
}; };
}; };
};
ingresses.pihole-web = { lab.ingresses.pihole = {
metadata.annotations = { host = "pihole.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "pihole-web";
portName = "web";
rules = [{
host = "pihole.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "pihole-web";
port.name = "web";
};
}];
}];
tls = [{
secretName = "pihole-tls";
hosts = [ "pihole.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -98,32 +98,14 @@
targetPort = "web"; targetPort = "web";
}; };
}; };
};
ingresses.radicale = { lab.ingresses.radicale = {
metadata.annotations."cert-manager.io/cluster-issuer" = "letsencrypt"; host = "dav.kun.is";
spec = { service = {
ingressClassName = "traefik"; name = "radicale";
portName = "web";
rules = [{
host = "dav.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "radicale";
port.name = "web";
};
}];
}];
tls = [{
secretName = "radicale-tls";
hosts = [ "dav.kun.is" ];
}];
};
}; };
}; };
} }

View file

@ -67,35 +67,15 @@
targetPort = "web"; targetPort = "web";
}; };
}; };
};
ingresses.syncthing = { lab.ingresses.syncthing = {
metadata.annotations = { host = "sync.kun.is";
"cert-manager.io/cluster-issuer" = "letsencrypt"; entrypoint = "localsecure";
"traefik.ingress.kubernetes.io/router.entrypoints" = "localsecure";
};
spec = { service = {
ingressClassName = "traefik"; name = "syncthing";
portName = "web";
rules = [{
host = "sync.kun.is";
http.paths = [{
path = "/";
pathType = "Prefix";
backend.service = {
name = "syncthing";
port.name = "web";
};
}];
}];
tls = [{
secretName = "syncthing-tls";
hosts = [ "sync.kun.is" ];
}];
};
}; };
}; };
} }