2023-05-10 17:21:47 +00:00
|
|
|
# Module to run some infra-specific things like updating the public ip
|
2024-01-23 20:30:39 +00:00
|
|
|
variable "git_user" {}
|
|
|
|
|
variable "git_token" {}
|
|
|
|
|
variable "technitium_username" {}
|
|
|
|
|
variable "technitium_password" {}
|
[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-05-10 17:21:47 +00:00
|
|
|
|
|
|
|
|
|
2024-12-15 18:04:32 +00:00
|
|
|
# DISABLED WHILST USING CLOUDFLARE NS
|
|
|
|
|
# resource "kubernetes_cron_job_v1" "update-public-ip" {
|
|
|
|
|
# metadata {
|
|
|
|
|
# name = "update-public-ip"
|
|
|
|
|
# namespace = "default"
|
|
|
|
|
# }
|
|
|
|
|
# spec {
|
|
|
|
|
# schedule = "*/5 * * * *"
|
|
|
|
|
# successful_jobs_history_limit = 1
|
|
|
|
|
# failed_jobs_history_limit = 1
|
|
|
|
|
# concurrency_policy = "Forbid"
|
|
|
|
|
# job_template {
|
|
|
|
|
# metadata {
|
|
|
|
|
# name = "update-public-ip"
|
|
|
|
|
# }
|
|
|
|
|
# spec {
|
|
|
|
|
# template {
|
|
|
|
|
# metadata {
|
|
|
|
|
# name = "update-public-ip"
|
|
|
|
|
# }
|
|
|
|
|
# spec {
|
|
|
|
|
# priority_class_name = "system-cluster-critical"
|
|
|
|
|
# container {
|
|
|
|
|
# name = "update-public-ip"
|
|
|
|
|
# image = "viktorbarzin/infra"
|
|
|
|
|
# command = ["./infra_cli"]
|
|
|
|
|
# args = ["-use-case", "update-public-ip"]
|
2023-05-10 17:43:16 +00:00
|
|
|
|
2024-12-15 18:04:32 +00:00
|
|
|
# env {
|
|
|
|
|
# name = "GIT_USER"
|
|
|
|
|
# value = var.git_user
|
|
|
|
|
# }
|
|
|
|
|
# env {
|
|
|
|
|
# name = "GIT_TOKEN"
|
|
|
|
|
# value = var.git_token
|
|
|
|
|
# }
|
|
|
|
|
# env {
|
|
|
|
|
# name = "TECHNITIUM_USERNAME"
|
|
|
|
|
# value = var.technitium_username
|
|
|
|
|
# }
|
|
|
|
|
# env {
|
|
|
|
|
# name = "TECHNITIUM_PASSWORD"
|
|
|
|
|
# value = var.technitium_password
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
# restart_policy = "Never"
|
|
|
|
|
# # service_account_name = "descheduler-sa"
|
|
|
|
|
# # volume {
|
|
|
|
|
# # name = "policy-volume"
|
|
|
|
|
# # config_map {
|
|
|
|
|
# # name = "policy-configmap"
|
|
|
|
|
# # }
|
|
|
|
|
# # }
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
# }
|
2024-08-03 16:47:57 +00:00
|
|
|
|
[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_etcd_backup" {
|
|
|
|
|
source = "../../../../modules/kubernetes/nfs_volume"
|
|
|
|
|
name = "infra-etcd-backup"
|
|
|
|
|
namespace = "default"
|
|
|
|
|
nfs_server = var.nfs_server
|
|
|
|
|
nfs_path = "/mnt/main/etcd-backup"
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-15 18:04:32 +00:00
|
|
|
# # backup etcd
|
2024-08-03 16:47:57 +00:00
|
|
|
resource "kubernetes_cron_job_v1" "backup-etcd" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "backup-etcd"
|
|
|
|
|
namespace = "default"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
schedule = "0 0 * * *"
|
|
|
|
|
successful_jobs_history_limit = 1
|
|
|
|
|
failed_jobs_history_limit = 1
|
|
|
|
|
concurrency_policy = "Forbid"
|
|
|
|
|
job_template {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "backup-etcd"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "backup-etcd"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
node_name = "k8s-master"
|
|
|
|
|
priority_class_name = "system-cluster-critical"
|
|
|
|
|
host_network = true
|
|
|
|
|
container {
|
|
|
|
|
name = "backup-etcd"
|
[ci skip] iSCSI migration, healthcheck fixes, health probes, etcd backup
- Migrate MySQL/PostgreSQL storage from local-path to iscsi-truenas
- Add democratic-csi iSCSI driver module for TrueNAS
- Add open-iscsi to cloud-init VM template
- Fix Shlink health probe path (/api/v3 -> /rest/v3 for Shlink 5.0)
- Fix etcd backup: use etcd 3.5.21-0 (3.6.x is distroless, no /bin/sh)
- Fix cluster healthcheck CronJob: always exit 0 to prevent circular
JobFailed alerts (reporting via Slack, not exit codes)
- Fix Uptime Kuma nested list handling in cluster-health.sh
- Add health probes to: audiobookshelf, immich ML, ntfy, headscale,
uptime-kuma, vaultwarden, rybbit (clickhouse + server + client),
shlink, shlink-web
- Add iSCSI storage documentation to CLAUDE.md
2026-03-06 19:54:21 +00:00
|
|
|
image = "registry.k8s.io/etcd:3.5.21-0"
|
2026-03-19 20:23:59 +00:00
|
|
|
command = ["/bin/sh", "-c"]
|
|
|
|
|
args = ["ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 --cacert=/etc/kubernetes/pki/etcd/ca.crt --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt --key=/etc/kubernetes/pki/etcd/healthcheck-client.key snapshot save /backup/etcd-snapshot-$(date +%Y%m%d-%H%M%S).db"]
|
2024-08-03 16:47:57 +00:00
|
|
|
env {
|
|
|
|
|
name = "ETCDCTL_API"
|
|
|
|
|
value = "3"
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
mount_path = "/backup"
|
|
|
|
|
name = "backup"
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
mount_path = "/etc/kubernetes/pki/etcd"
|
|
|
|
|
name = "etcd-certs"
|
|
|
|
|
read_only = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
container {
|
|
|
|
|
name = "backup-purge"
|
|
|
|
|
image = "busybox:1.31.1"
|
|
|
|
|
command = ["/bin/sh"]
|
|
|
|
|
args = ["-c", "find /backup -type f -mtime +30 -name '*.db' -exec rm -- '{}' \\;"]
|
|
|
|
|
|
|
|
|
|
volume_mount {
|
|
|
|
|
mount_path = "/backup"
|
|
|
|
|
name = "backup"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume {
|
|
|
|
|
name = "backup"
|
[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_etcd_backup.claim_name
|
2024-08-03 16:47:57 +00:00
|
|
|
}
|
2026-03-15 17:23:39 +00:00
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "etcd-certs"
|
|
|
|
|
host_path {
|
|
|
|
|
path = "/etc/kubernetes/pki/etcd"
|
|
|
|
|
type = "DirectoryOrCreate"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
restart_policy = "Never"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Weekly etcd defragmentation — prevents fragmentation buildup that causes slow requests
|
|
|
|
|
resource "kubernetes_cron_job_v1" "defrag-etcd" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "defrag-etcd"
|
|
|
|
|
namespace = "default"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
schedule = "0 3 * * 0"
|
|
|
|
|
successful_jobs_history_limit = 1
|
|
|
|
|
failed_jobs_history_limit = 1
|
|
|
|
|
concurrency_policy = "Forbid"
|
|
|
|
|
job_template {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "defrag-etcd"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "defrag-etcd"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
node_name = "k8s-master"
|
|
|
|
|
priority_class_name = "system-cluster-critical"
|
|
|
|
|
host_network = true
|
|
|
|
|
container {
|
|
|
|
|
name = "defrag-etcd"
|
|
|
|
|
image = "registry.k8s.io/etcd:3.5.21-0"
|
|
|
|
|
command = ["etcdctl"]
|
2026-03-15 17:24:24 +00:00
|
|
|
args = ["--endpoints=https://127.0.0.1:2379", "--cacert=/etc/kubernetes/pki/etcd/ca.crt", "--cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt", "--key=/etc/kubernetes/pki/etcd/healthcheck-client.key", "--command-timeout=60s", "defrag"]
|
2026-03-15 17:23:39 +00:00
|
|
|
env {
|
|
|
|
|
name = "ETCDCTL_API"
|
|
|
|
|
value = "3"
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
mount_path = "/etc/kubernetes/pki/etcd"
|
|
|
|
|
name = "etcd-certs"
|
|
|
|
|
read_only = true
|
|
|
|
|
}
|
2024-08-03 16:47:57 +00:00
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "etcd-certs"
|
|
|
|
|
host_path {
|
|
|
|
|
path = "/etc/kubernetes/pki/etcd"
|
|
|
|
|
type = "DirectoryOrCreate"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
restart_policy = "Never"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-15 17:20:47 +00:00
|
|
|
|
|
|
|
|
# Clean up evicted/failed pods cluster-wide daily
|
|
|
|
|
resource "kubernetes_cron_job_v1" "cleanup-failed-pods" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "cleanup-failed-pods"
|
|
|
|
|
namespace = "default"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
schedule = "0 2 * * *"
|
|
|
|
|
successful_jobs_history_limit = 1
|
|
|
|
|
failed_jobs_history_limit = 1
|
|
|
|
|
concurrency_policy = "Forbid"
|
|
|
|
|
job_template {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "cleanup-failed-pods"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "cleanup-failed-pods"
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
service_account_name = kubernetes_service_account.cleanup_sa.metadata[0].name
|
|
|
|
|
container {
|
|
|
|
|
name = "cleanup"
|
|
|
|
|
image = "bitnami/kubectl:latest"
|
|
|
|
|
command = ["/bin/sh", "-c", "kubectl delete pods -A --field-selector=status.phase=Failed --ignore-not-found"]
|
|
|
|
|
}
|
|
|
|
|
restart_policy = "Never"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service_account" "cleanup_sa" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "failed-pod-cleanup"
|
|
|
|
|
namespace = "default"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_cluster_role" "cleanup_role" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "failed-pod-cleanup"
|
|
|
|
|
}
|
|
|
|
|
rule {
|
|
|
|
|
api_groups = [""]
|
|
|
|
|
resources = ["pods"]
|
|
|
|
|
verbs = ["list", "delete"]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_cluster_role_binding" "cleanup_binding" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "failed-pod-cleanup"
|
|
|
|
|
}
|
|
|
|
|
role_ref {
|
|
|
|
|
api_group = "rbac.authorization.k8s.io"
|
|
|
|
|
kind = "ClusterRole"
|
|
|
|
|
name = kubernetes_cluster_role.cleanup_role.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
subject {
|
|
|
|
|
kind = "ServiceAccount"
|
|
|
|
|
name = kubernetes_service_account.cleanup_sa.metadata[0].name
|
|
|
|
|
namespace = "default"
|
|
|
|
|
}
|
|
|
|
|
}
|