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:59:58 +00:00
|
|
|
# Redis with Sentinel HA via Bitnami Helm chart
|
|
|
|
|
# Architecture: 1 master + 2 replicas + 3 sentinels
|
|
|
|
|
# Sentinel automatically promotes a replica if master fails
|
|
|
|
|
# The K8s Service always points at the current master
|
|
|
|
|
resource "helm_release" "redis" {
|
|
|
|
|
namespace = kubernetes_namespace.redis.metadata[0].name
|
|
|
|
|
create_namespace = false
|
|
|
|
|
name = "redis"
|
|
|
|
|
atomic = true
|
|
|
|
|
timeout = 600
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
repository = "oci://10.0.20.10:5000/bitnamicharts"
|
|
|
|
|
chart = "redis"
|
|
|
|
|
version = "25.3.2"
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
values = [yamlencode({
|
|
|
|
|
architecture = "replication"
|
|
|
|
|
|
|
|
|
|
auth = {
|
|
|
|
|
enabled = false
|
2025-11-10 22:40:28 +00:00
|
|
|
}
|
2026-02-28 19:59:58 +00:00
|
|
|
|
|
|
|
|
sentinel = {
|
2026-02-28 21:59:08 +00:00
|
|
|
enabled = true
|
|
|
|
|
quorum = 2
|
|
|
|
|
masterSet = "mymaster"
|
|
|
|
|
automateCluster = true
|
2026-02-28 19:59:58 +00:00
|
|
|
|
|
|
|
|
resources = {
|
|
|
|
|
requests = {
|
|
|
|
|
cpu = "50m"
|
|
|
|
|
memory = "64Mi"
|
|
|
|
|
}
|
|
|
|
|
limits = {
|
|
|
|
|
cpu = "200m"
|
|
|
|
|
memory = "128Mi"
|
|
|
|
|
}
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-28 19:59:58 +00:00
|
|
|
|
|
|
|
|
master = {
|
|
|
|
|
persistence = {
|
|
|
|
|
enabled = true
|
|
|
|
|
storageClass = "local-path"
|
|
|
|
|
size = "2Gi"
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
resources = {
|
|
|
|
|
requests = {
|
2026-02-28 21:59:08 +00:00
|
|
|
cpu = "100m"
|
|
|
|
|
memory = "64Mi"
|
2026-02-28 19:59:58 +00:00
|
|
|
}
|
|
|
|
|
limits = {
|
2026-02-28 21:59:08 +00:00
|
|
|
cpu = "500m"
|
|
|
|
|
memory = "256Mi"
|
2026-02-28 19:59:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-04 01:07:41 +00:00
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
replica = {
|
|
|
|
|
replicaCount = 2
|
[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
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
persistence = {
|
|
|
|
|
enabled = true
|
|
|
|
|
storageClass = "local-path"
|
|
|
|
|
size = "2Gi"
|
|
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
resources = {
|
|
|
|
|
requests = {
|
2026-02-28 21:59:08 +00:00
|
|
|
cpu = "50m"
|
|
|
|
|
memory = "64Mi"
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
2026-02-28 19:59:58 +00:00
|
|
|
limits = {
|
|
|
|
|
cpu = "500m"
|
2026-02-28 21:59:08 +00:00
|
|
|
memory = "256Mi"
|
2026-02-23 22:43:05 +00:00
|
|
|
}
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
# Metrics for Prometheus
|
|
|
|
|
metrics = {
|
|
|
|
|
enabled = false
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
2026-02-28 19:59:58 +00:00
|
|
|
|
|
|
|
|
# Use the existing service name so clients don't need changes
|
|
|
|
|
# Sentinel-enabled Bitnami chart creates a headless service
|
|
|
|
|
# and a regular service pointing at the master
|
|
|
|
|
nameOverride = "redis"
|
|
|
|
|
})]
|
2023-11-04 01:07:41 +00:00
|
|
|
}
|
2026-02-28 19:44:08 +00:00
|
|
|
|
2026-02-28 19:59:58 +00:00
|
|
|
# Hourly backup: copy RDB snapshot from master to NFS
|
2026-02-28 19:44:08 +00:00
|
|
|
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
|
2026-02-28 19:59:58 +00:00
|
|
|
# Trigger a fresh RDB save on the master
|
2026-02-28 19:44:08 +00:00
|
|
|
redis-cli -h redis.redis BGSAVE
|
|
|
|
|
sleep 5
|
2026-02-28 19:59:58 +00:00
|
|
|
# Copy the RDB via redis-cli --rdb
|
2026-02-28 19:44:08 +00:00
|
|
|
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
|
|
|
}
|