diff --git a/apps/jeannie-api/endpoints.yaml b/apps/jeannie-api/endpoints.yaml new file mode 100644 index 0000000..117f2bf --- /dev/null +++ b/apps/jeannie-api/endpoints.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Endpoints +metadata: + name: jeannie-api + namespace: jeannie-api +subsets: + - addresses: + - ip: 192.168.100.73 + ports: + - name: http + port: 8787 + protocol: TCP diff --git a/apps/jeannie-api/ingress.yaml b/apps/jeannie-api/ingress.yaml new file mode 100644 index 0000000..0b09336 --- /dev/null +++ b/apps/jeannie-api/ingress.yaml @@ -0,0 +1,55 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: jeannie-api-read + namespace: jeannie-api + annotations: + traefik.ingress.kubernetes.io/router.middlewares: jeannie-api-jeannie-api-auth@kubernetescrd,jeannie-api-jeannie-api-rate-limit@kubernetescrd,jeannie-api-jeannie-api-read-retry@kubernetescrd +spec: + ingressClassName: traefik + rules: + - host: api.lab2025.duckdns.org + http: + paths: + - path: /v1/health + pathType: Exact + backend: + service: + name: jeannie-api + port: + number: 8787 + - path: /v1/commands + pathType: Exact + backend: + service: + name: jeannie-api + port: + number: 8787 + - path: /v1/executions + pathType: Prefix + backend: + service: + name: jeannie-api + port: + number: 8787 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: jeannie-api-execute + namespace: jeannie-api + annotations: + traefik.ingress.kubernetes.io/router.middlewares: jeannie-api-jeannie-api-auth@kubernetescrd,jeannie-api-jeannie-api-rate-limit@kubernetescrd +spec: + ingressClassName: traefik + rules: + - host: api.lab2025.duckdns.org + http: + paths: + - path: /v1/execute + pathType: Exact + backend: + service: + name: jeannie-api + port: + number: 8787 diff --git a/apps/jeannie-api/kustomization.yaml b/apps/jeannie-api/kustomization.yaml new file mode 100644 index 0000000..8fea451 --- /dev/null +++ b/apps/jeannie-api/kustomization.yaml @@ -0,0 +1,9 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - namespace.yaml + - service.yaml + - endpoints.yaml + - transport.yaml + - middleware.yaml + - ingress.yaml diff --git a/apps/jeannie-api/middleware.yaml b/apps/jeannie-api/middleware.yaml new file mode 100644 index 0000000..792fdf4 --- /dev/null +++ b/apps/jeannie-api/middleware.yaml @@ -0,0 +1,32 @@ +apiVersion: traefik.io/v1alpha1 +kind: Middleware +metadata: + name: jeannie-api-auth + namespace: jeannie-api +spec: + forwardAuth: + address: http://jeannie-api.jeannie-api.svc.cluster.local:8787/v1/health + authRequestHeaders: + - Authorization + trustForwardHeader: false +--- +apiVersion: traefik.io/v1alpha1 +kind: Middleware +metadata: + name: jeannie-api-rate-limit + namespace: jeannie-api +spec: + rateLimit: + average: 10 + burst: 20 + period: 1s +--- +apiVersion: traefik.io/v1alpha1 +kind: Middleware +metadata: + name: jeannie-api-read-retry + namespace: jeannie-api +spec: + retry: + attempts: 2 + initialInterval: 100ms diff --git a/apps/jeannie-api/namespace.yaml b/apps/jeannie-api/namespace.yaml new file mode 100644 index 0000000..5ef2cb5 --- /dev/null +++ b/apps/jeannie-api/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: jeannie-api diff --git a/apps/jeannie-api/service.yaml b/apps/jeannie-api/service.yaml new file mode 100644 index 0000000..a74836e --- /dev/null +++ b/apps/jeannie-api/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: jeannie-api + namespace: jeannie-api + annotations: + traefik.ingress.kubernetes.io/service.serverstransport: jeannie-api-jeannie-api-backend@kubernetescrd +spec: + clusterIP: None + ports: + - name: http + port: 8787 + targetPort: 8787 + protocol: TCP diff --git a/apps/jeannie-api/transport.yaml b/apps/jeannie-api/transport.yaml new file mode 100644 index 0000000..3cb3e2a --- /dev/null +++ b/apps/jeannie-api/transport.yaml @@ -0,0 +1,10 @@ +apiVersion: traefik.io/v1alpha1 +kind: ServersTransport +metadata: + name: jeannie-api-backend + namespace: jeannie-api +spec: + forwardingTimeouts: + dialTimeout: 3s + responseHeaderTimeout: 30s + idleConnTimeout: 60s diff --git a/bootstrap/apps/variables.tf b/bootstrap/apps/variables.tf index 02d387c..c0b494e 100644 --- a/bootstrap/apps/variables.tf +++ b/bootstrap/apps/variables.tf @@ -58,6 +58,15 @@ variable "applications" { self_heal = true create_namespace = true } + jeannie-api = { + project = "default" + path = "apps/jeannie-api" + namespace = "jeannie-api" + target_revision = "main" + prune = true + self_heal = true + create_namespace = true + } website-production = { project = "default" path = "apps/website" diff --git a/bootstrap/platform/main.tf b/bootstrap/platform/main.tf index 667ddd9..379c432 100644 --- a/bootstrap/platform/main.tf +++ b/bootstrap/platform/main.tf @@ -983,7 +983,21 @@ resource "helm_release" "traefik" { enabled = true } } + metrics = { + prometheus = { + entryPoint = "metrics" + addEntryPointsLabels = true + addServicesLabels = true + } + } ports = { + metrics = { + port = 9100 + expose = { + default = true + } + exposedPort = 9100 + } web = { port = 8000 exposedPort = 80 @@ -1007,6 +1021,10 @@ resource "helm_release" "traefik" { general = { level = "INFO" } + access = { + enabled = true + format = "json" + } } resources = { requests = { @@ -2004,6 +2022,25 @@ resource "helm_release" "prometheus_stack" { target_label = "instance" } ] + }, + { + job_name = "traefik" + static_configs = [ + { + targets = ["traefik.${var.traefik.namespace}.svc:9100"] + labels = { + host_group = "ingress" + } + } + ] + metrics_path = "/metrics" + scheme = "http" + relabel_configs = [ + { + source_labels = ["__address__"] + target_label = "instance" + } + ] } ]) resources = { diff --git a/docs/jeannie-remote-api.md b/docs/jeannie-remote-api.md index 4564a4e..78afc0e 100644 --- a/docs/jeannie-remote-api.md +++ b/docs/jeannie-remote-api.md @@ -24,3 +24,28 @@ The initial allowlist contains read-only commands only. Execution state is stored in memory and command output is returned through GET /v1/executions/{id}. It is not a public edge service and does not accept arbitrary shell commands. + +## Kubernetes API gateway + +The `jeannie-api` Argo application publishes the Debian API through Traefik +at `api.lab2025.duckdns.org`. The backend remains the Debian host at +`192.168.100.73:8787`; Kubernetes does not run a second Jeannie server. + +The gateway applies the existing bearer-token authentication, a rate limit of +10 requests per second with a burst of 20, and backend timeouts of 3 seconds +for dialing, 30 seconds for response headers, and 60 seconds for idle +connections. Read-only routes may be retried once; `POST /v1/execute` is not +retried so a command cannot be submitted twice by the gateway. + +Traefik exposes JSON access logs and Prometheus request metrics. Prometheus +scrapes the Traefik metrics endpoint as the `traefik` job, with entrypoint and +service labels enabled. + +For a LAN test after the edge/DNS certificate is available, use the host's +LAN address or a local DNS override. Direct backend testing remains: + + curl -H 'Authorization: Bearer replace-with-a-secret' \ + http://192.168.100.73:8787/v1/health + +Through the API gateway, use the API hostname and the Traefik load-balancer +address from the cluster network. diff --git a/homelab.yml b/homelab.yml index 621216a..e9e3801 100644 --- a/homelab.yml +++ b/homelab.yml @@ -29,6 +29,7 @@ domain: - kapowarr.lab2025.duckdns.org - suwayomi.lab2025.duckdns.org - maintainerr.lab2025.duckdns.org + - api.lab2025.duckdns.org network: lan_cidr: 192.168.100.0/24