2023-11-04 01:07:41 +00:00
|
|
|
variable "tls_secret_name" {}
|
2026-01-10 16:28:12 +00:00
|
|
|
variable "tier" { type = string }
|
[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 }
|
2023-11-04 01:07:41 +00:00
|
|
|
|
|
|
|
|
resource "kubernetes_namespace" "redis" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "redis"
|
2026-02-21 23:38:05 +00:00
|
|
|
labels = {
|
|
|
|
|
tier = var.tier
|
|
|
|
|
}
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "tls_secret" {
|
2026-02-22 14:38:14 +00:00
|
|
|
source = "../../../../modules/kubernetes/setup_tls_secret"
|
2025-12-29 10:23:42 +00:00
|
|
|
namespace = kubernetes_namespace.redis.metadata[0].name
|
2023-11-04 01:07:41 +00:00
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-28 19:44:08 +00:00
|
|
|
# Local PVC for Redis data — proper fsync, fast RDB saves
|
|
|
|
|
resource "kubernetes_persistent_volume_claim" "redis" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "redis-data"
|
|
|
|
|
namespace = kubernetes_namespace.redis.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
access_modes = ["ReadWriteOnce"]
|
|
|
|
|
storage_class_name = "local-path"
|
|
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
storage = "2Gi"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wait_until_bound = false
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 01:07:41 +00:00
|
|
|
resource "kubernetes_deployment" "redis" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "redis"
|
2025-12-29 10:23:42 +00:00
|
|
|
namespace = kubernetes_namespace.redis.metadata[0].name
|
2023-11-04 01:07:41 +00:00
|
|
|
labels = {
|
2026-01-10 16:28:12 +00:00
|
|
|
app = "redis"
|
|
|
|
|
tier = var.tier
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1
|
2025-11-10 22:40:28 +00:00
|
|
|
strategy {
|
|
|
|
|
type = "Recreate"
|
|
|
|
|
}
|
2023-11-04 01:07:41 +00:00
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
app = "redis"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
labels = {
|
|
|
|
|
app = "redis"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
2026-02-28 19:44:08 +00:00
|
|
|
# No init container needed — all Redis data is transient (queues, caches).
|
|
|
|
|
# Starting fresh is safe; services rebuild their state automatically.
|
|
|
|
|
|
2023-11-04 01:07:41 +00:00
|
|
|
container {
|
2026-02-28 19:44:08 +00:00
|
|
|
image = "redis:7-alpine"
|
2023-11-04 01:07:41 +00:00
|
|
|
name = "redis"
|
|
|
|
|
|
[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
|
|
|
resources {
|
|
|
|
|
requests = {
|
2026-02-23 22:37:56 +00:00
|
|
|
cpu = "200m"
|
2026-02-28 19:44:08 +00:00
|
|
|
memory = "512Mi"
|
[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
|
|
|
}
|
|
|
|
|
limits = {
|
2026-02-23 22:37:56 +00:00
|
|
|
cpu = "1"
|
|
|
|
|
memory = "2Gi"
|
[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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 01:07:41 +00:00
|
|
|
port {
|
|
|
|
|
container_port = 6379
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "data"
|
|
|
|
|
mount_path = "/data"
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2023-11-04 01:07:41 +00:00
|
|
|
volume {
|
|
|
|
|
name = "data"
|
2026-02-28 19:44:08 +00:00
|
|
|
persistent_volume_claim {
|
|
|
|
|
claim_name = kubernetes_persistent_volume_claim.redis.metadata[0].name
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2026-02-23 22:43:05 +00:00
|
|
|
dns_config {
|
|
|
|
|
option {
|
|
|
|
|
name = "ndots"
|
|
|
|
|
value = "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2023-11-04 01:07:41 +00:00
|
|
|
resource "kubernetes_service" "redis" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "redis"
|
2025-12-29 10:23:42 +00:00
|
|
|
namespace = kubernetes_namespace.redis.metadata[0].name
|
2023-11-04 01:07:41 +00:00
|
|
|
labels = {
|
|
|
|
|
app = "redis"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
app = "redis"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "redis"
|
|
|
|
|
port = 6379
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
|
|
|
|
# Hourly backup: copy RDB snapshot to NFS for the TrueNAS → backup NAS pipeline
|
|
|
|
|
resource "kubernetes_cron_job_v1" "redis-backup" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "redis-backup"
|
|
|
|
|
namespace = kubernetes_namespace.redis.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
concurrency_policy = "Replace"
|
|
|
|
|
failed_jobs_history_limit = 3
|
|
|
|
|
schedule = "0 * * * *"
|
|
|
|
|
starting_deadline_seconds = 10
|
|
|
|
|
successful_jobs_history_limit = 3
|
|
|
|
|
job_template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
|
|
|
|
backoff_limit = 2
|
|
|
|
|
ttl_seconds_after_finished = 60
|
|
|
|
|
template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
|
|
|
|
container {
|
|
|
|
|
name = "redis-backup"
|
|
|
|
|
image = "redis:7-alpine"
|
|
|
|
|
command = ["/bin/sh", "-c", <<-EOT
|
|
|
|
|
set -eux
|
|
|
|
|
# Trigger a fresh RDB save
|
|
|
|
|
redis-cli -h redis.redis BGSAVE
|
|
|
|
|
sleep 5
|
|
|
|
|
# Copy the RDB from the running pod's data via redis
|
|
|
|
|
redis-cli -h redis.redis --rdb /backup/dump.rdb
|
|
|
|
|
echo "Backup complete: $(ls -lh /backup/dump.rdb)"
|
|
|
|
|
EOT
|
|
|
|
|
]
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "backup"
|
|
|
|
|
mount_path = "/backup"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "backup"
|
|
|
|
|
nfs {
|
|
|
|
|
path = "/mnt/main/redis-backup"
|
|
|
|
|
server = var.nfs_server
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|