infra/stacks/frigate/main.tf
Viktor Barzin 89a6e08245 [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

216 lines
4.9 KiB
HCL

variable "tls_secret_name" { type = string }
variable "nfs_server" { type = string }
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
}
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 {
limits = {
"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"
}
security_context {
privileged = true
}
}
volume {
name = "config"
nfs {
path = "/mnt/main/frigate/config"
server = var.nfs_server
}
}
volume {
name = "dshm"
empty_dir {
medium = "Memory"
size_limit = "1Gi"
}
}
volume {
name = "media"
nfs {
path = "/mnt/main/frigate/media"
server = var.nfs_server
}
}
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"
tls_secret_name = var.tls_secret_name
protected = true
rybbit_site_id = "0d4044069ff5"
}
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
}