2026-03-07 14:30:36 +00:00
|
|
|
variable "tls_secret_name" {
|
2026-03-14 08:51:45 +00:00
|
|
|
type = string
|
2026-03-07 14:30:36 +00:00
|
|
|
sensitive = true
|
|
|
|
|
}
|
[ci skip] Infrastructure hardening: security, monitoring, reliability, maintainability
Phase 1 - Critical Security:
- Netbox: move hardcoded DB/superuser passwords to variables
- MeshCentral: disable public registration, add Authentik auth
- Traefik: disable insecure API dashboard (api.insecure=false)
- Traefik: configure forwarded headers with Cloudflare trusted IPs
Phase 2 - Security Hardening:
- Add security headers middleware (HSTS, X-Frame-Options, nosniff, etc.)
- Add Kyverno pod security policies in audit mode (privileged, host
namespaces, SYS_ADMIN, trusted registries)
- Tighten rate limiting (avg=10, burst=50)
- Add Authentik protection to grampsweb
Phase 3 - Monitoring & Alerting:
- Add critical service alerts (PostgreSQL, MySQL, Redis, Headscale,
Authentik, Loki)
- Increase Loki retention from 7 to 30 days (720h)
- Add predictive PV filling alert (predict_linear)
- Re-enable Hackmd and Privatebin down alerts
Phase 4 - Reliability:
- Add resource requests/limits to Redis, DBaaS, Technitium, Headscale,
Vaultwarden, Uptime Kuma
- Increase Alloy DaemonSet memory to 512Mi/1Gi
Phase 6 - Maintainability:
- Extract duplicated tiers locals to terragrunt.hcl generate block
(removed from 67 stacks)
- Replace hardcoded NFS IP 10.0.10.15 with var.nfs_server (114
instances across 63 files)
- Replace hardcoded Redis/PostgreSQL/MySQL/Ollama/mail host references
with variables across ~35 stacks
- Migrate xray raw ingress resources to ingress_factory modules
2026-02-23 22:05:28 +00:00
|
|
|
variable "nfs_server" { type = string }
|
2026-02-22 13:56:34 +00:00
|
|
|
|
|
|
|
|
|
2026-02-22 15:13:55 +00:00
|
|
|
resource "kubernetes_namespace" "frigate" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "frigate"
|
|
|
|
|
labels = {
|
|
|
|
|
tier = local.tiers.gpu
|
|
|
|
|
}
|
|
|
|
|
# labels = {
|
|
|
|
|
# "istio-injection" : "enabled"
|
|
|
|
|
# }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "tls_secret" {
|
|
|
|
|
source = "../../modules/kubernetes/setup_tls_secret"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
}
|
|
|
|
|
|
[ci skip] complete NFS CSI migration: complex stacks + platform modules
Migrate remaining multi-volume stacks and all platform modules from
inline NFS volumes to CSI-backed PV/PVC with nfs-truenas StorageClass
(soft,timeo=30,retrans=3 mount options).
Complex stacks: openclaw (4 vols), immich (8 vols), frigate (2 vols),
nextcloud (2 vols + old PV replaced), rybbit (1 vol)
Remaining stacks: affine, ebook2audiobook, f1-stream, osm_routing,
real-estate-crawler
Platform modules: monitoring (prometheus, loki, alertmanager PVs
converted from native NFS to CSI), redis, dbaas, technitium,
headscale, vaultwarden, uptime-kuma, mailserver, infra-maintenance
2026-03-02 01:24:07 +00:00
|
|
|
module "nfs_config" {
|
|
|
|
|
source = "../../modules/kubernetes/nfs_volume"
|
|
|
|
|
name = "frigate-config"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
nfs_server = var.nfs_server
|
|
|
|
|
nfs_path = "/mnt/main/frigate/config"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "nfs_media" {
|
|
|
|
|
source = "../../modules/kubernetes/nfs_volume"
|
|
|
|
|
name = "frigate-media"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
nfs_server = var.nfs_server
|
|
|
|
|
nfs_path = "/mnt/main/frigate/media"
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 15:13:55 +00:00
|
|
|
resource "kubernetes_deployment" "frigate" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "frigate"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
app = "frigate"
|
|
|
|
|
tier = local.tiers.gpu
|
|
|
|
|
}
|
|
|
|
|
annotations = {
|
|
|
|
|
"reloader.stakater.com/search" = "true"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1 # Temporarily disabled due to high power consumption
|
|
|
|
|
strategy {
|
|
|
|
|
type = "Recreate"
|
|
|
|
|
}
|
|
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
app = "frigate"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
labels = {
|
|
|
|
|
app = "frigate"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
node_selector = {
|
|
|
|
|
"gpu" : true
|
|
|
|
|
}
|
|
|
|
|
toleration {
|
|
|
|
|
key = "nvidia.com/gpu"
|
|
|
|
|
operator = "Equal"
|
|
|
|
|
value = "true"
|
|
|
|
|
effect = "NoSchedule"
|
|
|
|
|
}
|
|
|
|
|
container {
|
|
|
|
|
# image = "ghcr.io/blakeblackshear/frigate:stable"
|
|
|
|
|
# image = "ghcr.io/blakeblackshear/frigate:stable-tensorrt"
|
|
|
|
|
image = "ghcr.io/blakeblackshear/frigate:0.17.0-beta1-tensorrt"
|
|
|
|
|
name = "frigate"
|
|
|
|
|
|
|
|
|
|
resources {
|
[ci skip] right-size all pod resources based on VPA + live metrics audit
Full cluster resource audit: cross-referenced Goldilocks VPA recommendations,
live kubectl top metrics, and Terraform definitions for 100+ containers.
Critical fixes:
- dashy: CPU throttled at 98% (490m/500m) → 2 CPU limit
- stirling-pdf: CPU throttled at 99.7% (299m/300m) → 2 CPU limit
- traefik auth-proxy/bot-block-proxy: mem limit 32Mi → 128Mi
Added explicit resources to ~40 containers that had none:
- audiobookshelf, changedetection, cyberchef, dawarich, diun, echo,
excalidraw, freshrss, hackmd, isponsorblocktv, linkwarden, n8n,
navidrome, ntfy, owntracks, privatebin, send, shadowsocks, tandoor,
tor-proxy, wealthfolio, networking-toolbox, rybbit, mailserver,
cloudflared, pgadmin, phpmyadmin, crowdsec-web, xray, wireguard,
k8s-portal, tuya-bridge, ollama-ui, whisper, piper, immich-server,
immich-postgresql, osrm-foot
GPU containers: added CPU/mem alongside GPU limits:
- ollama: removed CPU/mem limits (models vary in size), keep GPU only
- frigate: req 500m/2Gi, lim 4/8Gi + GPU
- immich-ml: req 100m/1Gi, lim 2/4Gi + GPU
Right-sized ~25 over-provisioned containers:
- kms-web-page: 500m/512Mi → 50m/64Mi (was using 0m/10Mi)
- onlyoffice: CPU 8 → 2 (VPA upper 45m)
- realestate-crawler-api: CPU 2000m → 250m
- blog/travel-blog/webhook-handler: 500m → 100m
- coturn/health/plotting-book: reduced to match actual usage
Conservative methodology: limits = max(VPA upper * 2, live usage * 2)
2026-03-01 19:18:50 +00:00
|
|
|
requests = {
|
Right-size CPU requests cluster-wide and remove missed CPU limits
Increase requests for under-requested pods (dashy 50m→250m, frigate 500m→1500m,
clickhouse 100m→500m, otp 100m→300m, linkwarden 25m→50m, authentik worker 50m→100m).
Reduce requests for over-requested pods (crowdsec agent/lapi 500m→25m each,
prometheus 200m→100m, dbaas mysql 1800m→100m, pg-cluster 250m→50m,
shlink-web 250m→10m, gpu-pod-exporter 50m→10m, stirling-pdf 100m→25m,
technitium 100m→25m, celery 50m→15m). Reduce crowdsec quota from 8→1 CPU.
Remove missed CPU limits in prometheus (cpu: "2") and dbaas (cpu: "3600m") tpl files.
2026-03-14 09:22:24 +00:00
|
|
|
cpu = "1500m"
|
2026-03-15 15:30:18 +00:00
|
|
|
memory = "5Gi"
|
[ci skip] right-size all pod resources based on VPA + live metrics audit
Full cluster resource audit: cross-referenced Goldilocks VPA recommendations,
live kubectl top metrics, and Terraform definitions for 100+ containers.
Critical fixes:
- dashy: CPU throttled at 98% (490m/500m) → 2 CPU limit
- stirling-pdf: CPU throttled at 99.7% (299m/300m) → 2 CPU limit
- traefik auth-proxy/bot-block-proxy: mem limit 32Mi → 128Mi
Added explicit resources to ~40 containers that had none:
- audiobookshelf, changedetection, cyberchef, dawarich, diun, echo,
excalidraw, freshrss, hackmd, isponsorblocktv, linkwarden, n8n,
navidrome, ntfy, owntracks, privatebin, send, shadowsocks, tandoor,
tor-proxy, wealthfolio, networking-toolbox, rybbit, mailserver,
cloudflared, pgadmin, phpmyadmin, crowdsec-web, xray, wireguard,
k8s-portal, tuya-bridge, ollama-ui, whisper, piper, immich-server,
immich-postgresql, osrm-foot
GPU containers: added CPU/mem alongside GPU limits:
- ollama: removed CPU/mem limits (models vary in size), keep GPU only
- frigate: req 500m/2Gi, lim 4/8Gi + GPU
- immich-ml: req 100m/1Gi, lim 2/4Gi + GPU
Right-sized ~25 over-provisioned containers:
- kms-web-page: 500m/512Mi → 50m/64Mi (was using 0m/10Mi)
- onlyoffice: CPU 8 → 2 (VPA upper 45m)
- realestate-crawler-api: CPU 2000m → 250m
- blog/travel-blog/webhook-handler: 500m → 100m
- coturn/health/plotting-book: reduced to match actual usage
Conservative methodology: limits = max(VPA upper * 2, live usage * 2)
2026-03-01 19:18:50 +00:00
|
|
|
}
|
2026-02-22 15:13:55 +00:00
|
|
|
limits = {
|
2026-03-15 15:30:18 +00:00
|
|
|
memory = "10Gi"
|
2026-02-22 15:13:55 +00:00
|
|
|
"nvidia.com/gpu" = "1"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
env {
|
|
|
|
|
name = "FRIGATE_RTSP_PASSWORD"
|
|
|
|
|
value = "password"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
container_port = 5000
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
container_port = 8554
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
container_port = 8555
|
|
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
container_port = 8555
|
|
|
|
|
protocol = "UDP"
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "config"
|
|
|
|
|
mount_path = "/config"
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "dri"
|
|
|
|
|
mount_path = "/dev/dri"
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "dshm"
|
|
|
|
|
mount_path = "/dev/shm"
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "media"
|
|
|
|
|
mount_path = "/media/frigate"
|
|
|
|
|
}
|
2026-03-13 10:23:21 +00:00
|
|
|
# Restart pod if GPU becomes unavailable, Frigate hangs, or
|
|
|
|
|
# detector falls back to CPU (inference time spikes from ~20ms to 200ms+)
|
2026-03-01 20:36:49 +00:00
|
|
|
liveness_probe {
|
|
|
|
|
exec {
|
2026-03-13 10:23:21 +00:00
|
|
|
command = ["sh", "-c", <<-EOT
|
|
|
|
|
nvidia-smi > /dev/null 2>&1 || exit 1
|
|
|
|
|
STATS=$(curl -sf --max-time 5 http://localhost:5000/api/stats) || exit 1
|
|
|
|
|
echo "$STATS" | python3 -c "
|
|
|
|
|
import sys, json
|
|
|
|
|
stats = json.load(sys.stdin)
|
|
|
|
|
for name, det in stats.get('detectors', {}).items():
|
|
|
|
|
speed = det.get('inference_speed', 0)
|
|
|
|
|
if speed > 100:
|
|
|
|
|
print(f'UNHEALTHY: detector {name} inference {speed}ms > 100ms threshold')
|
|
|
|
|
sys.exit(1)
|
|
|
|
|
"
|
|
|
|
|
EOT
|
|
|
|
|
]
|
2026-03-01 20:36:49 +00:00
|
|
|
}
|
|
|
|
|
initial_delay_seconds = 120
|
|
|
|
|
period_seconds = 60
|
|
|
|
|
timeout_seconds = 10
|
|
|
|
|
failure_threshold = 3
|
|
|
|
|
}
|
|
|
|
|
# TensorRT model loading can take several minutes
|
|
|
|
|
startup_probe {
|
|
|
|
|
http_get {
|
|
|
|
|
path = "/api/version"
|
|
|
|
|
port = 5000
|
|
|
|
|
}
|
|
|
|
|
period_seconds = 10
|
|
|
|
|
failure_threshold = 30 # up to 5 minutes for startup
|
|
|
|
|
}
|
2026-02-22 15:13:55 +00:00
|
|
|
security_context {
|
|
|
|
|
privileged = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume {
|
|
|
|
|
name = "config"
|
[ci skip] complete NFS CSI migration: complex stacks + platform modules
Migrate remaining multi-volume stacks and all platform modules from
inline NFS volumes to CSI-backed PV/PVC with nfs-truenas StorageClass
(soft,timeo=30,retrans=3 mount options).
Complex stacks: openclaw (4 vols), immich (8 vols), frigate (2 vols),
nextcloud (2 vols + old PV replaced), rybbit (1 vol)
Remaining stacks: affine, ebook2audiobook, f1-stream, osm_routing,
real-estate-crawler
Platform modules: monitoring (prometheus, loki, alertmanager PVs
converted from native NFS to CSI), redis, dbaas, technitium,
headscale, vaultwarden, uptime-kuma, mailserver, infra-maintenance
2026-03-02 01:24:07 +00:00
|
|
|
persistent_volume_claim {
|
|
|
|
|
claim_name = module.nfs_config.claim_name
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "dshm"
|
|
|
|
|
empty_dir {
|
|
|
|
|
medium = "Memory"
|
|
|
|
|
size_limit = "1Gi"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "media"
|
[ci skip] complete NFS CSI migration: complex stacks + platform modules
Migrate remaining multi-volume stacks and all platform modules from
inline NFS volumes to CSI-backed PV/PVC with nfs-truenas StorageClass
(soft,timeo=30,retrans=3 mount options).
Complex stacks: openclaw (4 vols), immich (8 vols), frigate (2 vols),
nextcloud (2 vols + old PV replaced), rybbit (1 vol)
Remaining stacks: affine, ebook2audiobook, f1-stream, osm_routing,
real-estate-crawler
Platform modules: monitoring (prometheus, loki, alertmanager PVs
converted from native NFS to CSI), redis, dbaas, technitium,
headscale, vaultwarden, uptime-kuma, mailserver, infra-maintenance
2026-03-02 01:24:07 +00:00
|
|
|
persistent_volume_claim {
|
|
|
|
|
claim_name = module.nfs_media.claim_name
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "dri"
|
|
|
|
|
host_path {
|
|
|
|
|
path = "/dev/dri"
|
|
|
|
|
type = "Directory"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "frigate" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "frigate"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
"app" = "frigate"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
app = "frigate"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
target_port = 5000
|
|
|
|
|
port = 80
|
|
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "frigate-rtsp" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "frigate-rtsp"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
"app" = "frigate"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
type = "NodePort" # Should always live on node1 where the gpu is
|
|
|
|
|
selector = {
|
|
|
|
|
app = "frigate"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "rtsp-tcp"
|
|
|
|
|
target_port = 8554
|
|
|
|
|
port = 8554
|
|
|
|
|
protocol = "TCP"
|
|
|
|
|
node_port = 30554
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "rtsp-udp"
|
|
|
|
|
target_port = 8554
|
|
|
|
|
port = 8554
|
|
|
|
|
protocol = "UDP"
|
|
|
|
|
node_port = 30554
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "ingress" {
|
|
|
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
name = "frigate"
|
2026-02-22 14:38:14 +00:00
|
|
|
tls_secret_name = var.tls_secret_name
|
2026-02-22 15:13:55 +00:00
|
|
|
protected = true
|
|
|
|
|
rybbit_site_id = "0d4044069ff5"
|
2026-03-07 16:41:36 +00:00
|
|
|
extra_annotations = {
|
|
|
|
|
"gethomepage.dev/enabled" = "true"
|
|
|
|
|
"gethomepage.dev/name" = "Frigate"
|
|
|
|
|
"gethomepage.dev/description" = "NVR & object detection"
|
|
|
|
|
"gethomepage.dev/icon" = "frigate.png"
|
|
|
|
|
"gethomepage.dev/group" = "Media & Entertainment"
|
|
|
|
|
"gethomepage.dev/pod-selector" = ""
|
|
|
|
|
"gethomepage.dev/widget.type" = "frigate"
|
2026-03-07 17:39:24 +00:00
|
|
|
"gethomepage.dev/widget.url" = "http://frigate.frigate.svc.cluster.local"
|
2026-03-07 16:41:36 +00:00
|
|
|
}
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "ingress-internal" {
|
|
|
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
|
|
|
namespace = kubernetes_namespace.frigate.metadata[0].name
|
|
|
|
|
name = "frigate-lan"
|
|
|
|
|
host = "frigate-lan"
|
|
|
|
|
root_domain = "viktorbarzin.lan"
|
|
|
|
|
service_name = "frigate"
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
allow_local_access_only = true
|
|
|
|
|
ssl_redirect = false
|
2026-03-07 16:41:36 +00:00
|
|
|
extra_annotations = {
|
|
|
|
|
"gethomepage.dev/enabled" = "false"
|
|
|
|
|
}
|
2026-02-22 13:56:34 +00:00
|
|
|
}
|