2026-03-07 14:30:36 +00:00
|
|
|
variable "tls_secret_name" {
|
2026-03-12 07:26:08 +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 }
|
|
|
|
|
variable "redis_host" { type = string }
|
|
|
|
|
variable "mysql_host" { type = string }
|
2026-03-14 17:15:48 +00:00
|
|
|
|
|
|
|
|
data "vault_kv_secret_v2" "secrets" {
|
|
|
|
|
mount = "secret"
|
|
|
|
|
name = "nextcloud"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
locals {
|
|
|
|
|
homepage_credentials = jsondecode(data.vault_kv_secret_v2.secrets.data["homepage_credentials"])
|
2026-03-07 19:03:06 +00:00
|
|
|
}
|
2026-02-22 13:56:34 +00:00
|
|
|
|
|
|
|
|
|
2026-02-22 15:13:55 +00:00
|
|
|
module "tls_secret" {
|
|
|
|
|
source = "../../modules/kubernetes/setup_tls_secret"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_namespace" "nextcloud" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "nextcloud"
|
|
|
|
|
labels = {
|
|
|
|
|
"istio-injection" : "disabled"
|
[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
|
|
|
tier = local.tiers.edge
|
2026-03-01 17:16:03 +00:00
|
|
|
"resource-governance/custom-limitrange" = "true"
|
2026-03-01 17:41:18 +00:00
|
|
|
"resource-governance/custom-quota" = "true"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
migrate consuming stacks to ESO + remove k8s-dashboard static token
Phase 9: ExternalSecret migration across 26 stacks:
Fully migrated (vault data source removed, ESO delivers secrets):
- speedtest, shadowsocks, wealthfolio, plotting-book, f1-stream, tandoor
- n8n, dawarich, diun, netbox, onlyoffice, tuya-bridge
- hackmd (ESO template for DB URL), health (ESO template for DB URL)
- trading-bot (ESO template for DATABASE_URL + 7 secret env vars)
- forgejo (removed unused vault data source)
Partially migrated (vault kept for plan-time, ESO added for runtime):
- immich, linkwarden, nextcloud, paperless-ngx (jsondecode for homepage)
- claude-memory, rybbit, url, webhook_handler (plan-time in locals/jobs)
- woodpecker, openclaw, resume (plan-time in helm values/jobs/modules)
17 stacks unchanged (all plan-time: homepage annotations, configmaps,
module inputs) — vault data source works with OIDC auth.
Phase 17a: Remove k8s-dashboard static admin token secret.
Users now get tokens via: vault write kubernetes/creds/dashboard-admin
2026-03-15 19:05:04 +00:00
|
|
|
resource "kubernetes_manifest" "external_secret" {
|
|
|
|
|
manifest = {
|
|
|
|
|
apiVersion = "external-secrets.io/v1beta1"
|
|
|
|
|
kind = "ExternalSecret"
|
|
|
|
|
metadata = {
|
|
|
|
|
name = "nextcloud-secrets"
|
|
|
|
|
namespace = "nextcloud"
|
|
|
|
|
}
|
|
|
|
|
spec = {
|
|
|
|
|
refreshInterval = "15m"
|
|
|
|
|
secretStoreRef = {
|
|
|
|
|
name = "vault-kv"
|
|
|
|
|
kind = "ClusterSecretStore"
|
|
|
|
|
}
|
|
|
|
|
target = {
|
|
|
|
|
name = "nextcloud-secrets"
|
|
|
|
|
}
|
|
|
|
|
dataFrom = [{
|
|
|
|
|
extract = {
|
|
|
|
|
key = "nextcloud"
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
depends_on = [kubernetes_namespace.nextcloud]
|
|
|
|
|
}
|
|
|
|
|
|
fix DB password desync + migrate remaining tfvars to Vault
DB desync fix: Stacks with Vault DB engine rotation (24h) now read
the password from vault-database ClusterSecretStore instead of vault-kv.
9 stacks updated with db ExternalSecrets reading from static-creds/*.
Stacks fixed: speedtest, hackmd, health, trading-bot, claude-memory,
woodpecker, linkwarden, nextcloud, url.
terraform.tfvars migration:
- plotting-book: google_client_id/secret → Vault KV + secret_key_ref
- tandoor: email_password var removed (was default="", now optional ESO)
- infra: ssh_private_key, vm_wizard_password, dockerhub_registry_password
→ Vault KV at secret/infra + data source
2026-03-15 21:39:45 +00:00
|
|
|
# DB credentials from Vault database engine (rotated every 24h)
|
2026-03-17 07:39:29 +00:00
|
|
|
# Nextcloud Helm chart reads password at runtime via existingSecret reference
|
fix DB password desync + migrate remaining tfvars to Vault
DB desync fix: Stacks with Vault DB engine rotation (24h) now read
the password from vault-database ClusterSecretStore instead of vault-kv.
9 stacks updated with db ExternalSecrets reading from static-creds/*.
Stacks fixed: speedtest, hackmd, health, trading-bot, claude-memory,
woodpecker, linkwarden, nextcloud, url.
terraform.tfvars migration:
- plotting-book: google_client_id/secret → Vault KV + secret_key_ref
- tandoor: email_password var removed (was default="", now optional ESO)
- infra: ssh_private_key, vm_wizard_password, dockerhub_registry_password
→ Vault KV at secret/infra + data source
2026-03-15 21:39:45 +00:00
|
|
|
resource "kubernetes_manifest" "db_external_secret" {
|
|
|
|
|
manifest = {
|
|
|
|
|
apiVersion = "external-secrets.io/v1beta1"
|
|
|
|
|
kind = "ExternalSecret"
|
|
|
|
|
metadata = {
|
|
|
|
|
name = "nextcloud-db-creds"
|
|
|
|
|
namespace = "nextcloud"
|
|
|
|
|
}
|
|
|
|
|
spec = {
|
|
|
|
|
refreshInterval = "15m"
|
|
|
|
|
secretStoreRef = {
|
|
|
|
|
name = "vault-database"
|
|
|
|
|
kind = "ClusterSecretStore"
|
|
|
|
|
}
|
|
|
|
|
target = {
|
|
|
|
|
name = "nextcloud-db-creds"
|
|
|
|
|
template = {
|
|
|
|
|
data = {
|
|
|
|
|
DB_PASSWORD = "{{ .password }}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
data = [{
|
|
|
|
|
secretKey = "password"
|
|
|
|
|
remoteRef = {
|
|
|
|
|
key = "static-creds/mysql-nextcloud"
|
|
|
|
|
property = "password"
|
|
|
|
|
}
|
|
|
|
|
}]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
depends_on = [kubernetes_namespace.nextcloud]
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-01 17:41:18 +00:00
|
|
|
resource "kubernetes_resource_quota" "nextcloud" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "nextcloud-quota"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
hard = {
|
|
|
|
|
"requests.cpu" = "4"
|
|
|
|
|
"requests.memory" = "8Gi"
|
|
|
|
|
"limits.memory" = "16Gi"
|
|
|
|
|
pods = "10"
|
2026-03-01 17:16:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_limit_range" "nextcloud" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "nextcloud-limits"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
limit {
|
|
|
|
|
type = "Container"
|
|
|
|
|
default = {
|
|
|
|
|
memory = "256Mi"
|
|
|
|
|
}
|
|
|
|
|
default_request = {
|
|
|
|
|
cpu = "25m"
|
|
|
|
|
memory = "64Mi"
|
|
|
|
|
}
|
|
|
|
|
max = {
|
|
|
|
|
memory = "8Gi"
|
|
|
|
|
}
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "helm_release" "nextcloud" {
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
name = "nextcloud"
|
|
|
|
|
|
|
|
|
|
repository = "https://nextcloud.github.io/helm/"
|
|
|
|
|
chart = "nextcloud"
|
|
|
|
|
atomic = true
|
|
|
|
|
version = "8.8.1"
|
|
|
|
|
|
2026-03-17 07:39:29 +00:00
|
|
|
values = [templatefile("${path.module}/chart_values.yaml", { tls_secret_name = var.tls_secret_name, redis_host = var.redis_host, mysql_host = var.mysql_host })]
|
|
|
|
|
timeout = 6000
|
|
|
|
|
depends_on = [kubernetes_manifest.db_external_secret]
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-08 21:33:27 +00:00
|
|
|
resource "kubernetes_config_map" "apache_tuning" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "nextcloud-apache-tuning"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
data = {
|
|
|
|
|
"mpm_prefork.conf" = <<-EOF
|
2026-03-13 18:59:21 +00:00
|
|
|
# Tuned for Nextcloud on MySQL (no SQLite lock contention)
|
|
|
|
|
# CPU/RAM usage is low (~20m/143Mi), so more workers are safe
|
2026-03-08 21:33:27 +00:00
|
|
|
<IfModule mpm_prefork_module>
|
2026-03-13 18:59:21 +00:00
|
|
|
StartServers 5
|
|
|
|
|
MinSpareServers 5
|
|
|
|
|
MaxSpareServers 15
|
|
|
|
|
MaxRequestWorkers 150
|
|
|
|
|
MaxConnectionsPerChild 500
|
2026-03-08 21:33:27 +00:00
|
|
|
</IfModule>
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 15:13:55 +00:00
|
|
|
# resource "kubernetes_config_map" "config" {
|
|
|
|
|
# metadata {
|
|
|
|
|
# name = "config"
|
|
|
|
|
# namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
|
|
|
|
|
# annotations = {
|
|
|
|
|
# "reloader.stakater.com/match" = "true"
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
# data = {
|
|
|
|
|
# "conf.yml" = file("${path.module}/conf.yml")
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
|
2026-03-11 23:23:37 +00:00
|
|
|
resource "kubernetes_persistent_volume_claim" "nextcloud_data_iscsi" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "nextcloud-data-iscsi"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
access_modes = ["ReadWriteOnce"]
|
|
|
|
|
storage_class_name = "iscsi-truenas"
|
|
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
storage = "20Gi"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
[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_nextcloud_backup" {
|
|
|
|
|
source = "../../modules/kubernetes/nfs_volume"
|
|
|
|
|
name = "nextcloud-backup"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
nfs_server = var.nfs_server
|
|
|
|
|
nfs_path = "/mnt/main/nextcloud-backup"
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-22 15:13:55 +00:00
|
|
|
resource "kubernetes_deployment" "whiteboard" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "whiteboard"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
app = "whiteboard"
|
|
|
|
|
tier = local.tiers.edge
|
|
|
|
|
}
|
|
|
|
|
annotations = {
|
|
|
|
|
"reloader.stakater.com/search" = "true"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1
|
|
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
app = "whiteboard"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
labels = {
|
|
|
|
|
app = "whiteboard"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
priority_class_name = "tier-3-edge"
|
|
|
|
|
container {
|
|
|
|
|
image = "ghcr.io/nextcloud-releases/whiteboard:release"
|
|
|
|
|
name = "whiteboard"
|
|
|
|
|
|
|
|
|
|
port {
|
|
|
|
|
container_port = 3002
|
|
|
|
|
}
|
|
|
|
|
env {
|
|
|
|
|
name = "NEXTCLOUD_URL"
|
|
|
|
|
value = "http://nextcloud:8080"
|
|
|
|
|
}
|
|
|
|
|
env {
|
migrate consuming stacks to ESO + remove k8s-dashboard static token
Phase 9: ExternalSecret migration across 26 stacks:
Fully migrated (vault data source removed, ESO delivers secrets):
- speedtest, shadowsocks, wealthfolio, plotting-book, f1-stream, tandoor
- n8n, dawarich, diun, netbox, onlyoffice, tuya-bridge
- hackmd (ESO template for DB URL), health (ESO template for DB URL)
- trading-bot (ESO template for DATABASE_URL + 7 secret env vars)
- forgejo (removed unused vault data source)
Partially migrated (vault kept for plan-time, ESO added for runtime):
- immich, linkwarden, nextcloud, paperless-ngx (jsondecode for homepage)
- claude-memory, rybbit, url, webhook_handler (plan-time in locals/jobs)
- woodpecker, openclaw, resume (plan-time in helm values/jobs/modules)
17 stacks unchanged (all plan-time: homepage annotations, configmaps,
module inputs) — vault data source works with OIDC auth.
Phase 17a: Remove k8s-dashboard static admin token secret.
Users now get tokens via: vault write kubernetes/creds/dashboard-admin
2026-03-15 19:05:04 +00:00
|
|
|
name = "JWT_SECRET_KEY"
|
|
|
|
|
value_from {
|
|
|
|
|
secret_key_ref {
|
|
|
|
|
name = "nextcloud-secrets"
|
|
|
|
|
key = "db_password"
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "whiteboard" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "whiteboard"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
app = "whiteboard"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
app = "whiteboard"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
port = 80
|
|
|
|
|
target_port = 3002
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "ingress" {
|
|
|
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
name = "nextcloud"
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
port = 8080
|
|
|
|
|
rybbit_site_id = "5a3bfe59a3fe"
|
2026-03-07 16:41:36 +00:00
|
|
|
extra_annotations = {
|
2026-03-12 07:26:08 +00:00
|
|
|
"gethomepage.dev/enabled" = "true"
|
|
|
|
|
"gethomepage.dev/name" = "Nextcloud"
|
|
|
|
|
"gethomepage.dev/description" = "Cloud productivity suite"
|
|
|
|
|
"gethomepage.dev/icon" = "nextcloud.png"
|
|
|
|
|
"gethomepage.dev/group" = "Productivity"
|
|
|
|
|
"gethomepage.dev/pod-selector" = ""
|
2026-03-07 19:03:06 +00:00
|
|
|
"gethomepage.dev/widget.type" = "nextcloud"
|
2026-03-07 19:36:25 +00:00
|
|
|
"gethomepage.dev/widget.url" = "https://nextcloud.viktorbarzin.me"
|
2026-03-14 17:15:48 +00:00
|
|
|
"gethomepage.dev/widget.username" = local.homepage_credentials["nextcloud"]["username"]
|
|
|
|
|
"gethomepage.dev/widget.password" = local.homepage_credentials["nextcloud"]["password"]
|
2026-03-07 16:41:36 +00:00
|
|
|
}
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "whiteboard_ingress" {
|
|
|
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
name = "whiteboard"
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
port = 80
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_config_map" "backup-script" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "nextcloud-backup-script"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data = {
|
|
|
|
|
"backup.sh" = <<-EOF
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
BACKUP_DIR="/backup"
|
|
|
|
|
DATA_DIR="/nextcloud-data"
|
|
|
|
|
DATE=$(date +%Y%m%d_%H%M%S)
|
|
|
|
|
BACKUP_PATH="$BACKUP_DIR/$DATE"
|
|
|
|
|
|
|
|
|
|
echo "Starting Nextcloud backup at $(date)"
|
|
|
|
|
|
|
|
|
|
# Note: Maintenance mode is skipped because occ is not available in the NFS mount.
|
|
|
|
|
# For a proper backup with maintenance mode, exec into the nextcloud pod:
|
|
|
|
|
# kubectl exec -n nextcloud deployment/nextcloud -- php occ maintenance:mode --on
|
|
|
|
|
|
|
|
|
|
# Create backup directory
|
|
|
|
|
mkdir -p "$BACKUP_PATH"
|
|
|
|
|
|
|
|
|
|
# Backup everything (config, data, custom_apps, themes, etc.)
|
|
|
|
|
echo "Backing up Nextcloud installation..."
|
|
|
|
|
rsync -a "$DATA_DIR/" "$BACKUP_PATH/"
|
|
|
|
|
|
|
|
|
|
# Keep only last 7 backups
|
|
|
|
|
echo "Cleaning old backups..."
|
|
|
|
|
cd "$BACKUP_DIR"
|
|
|
|
|
ls -dt */ | tail -n +8 | xargs -r rm -rf
|
|
|
|
|
|
|
|
|
|
echo "Backup completed at $(date)"
|
|
|
|
|
echo "Backup stored at: $BACKUP_PATH"
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
"restore.sh" = <<-EOF
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
# Restore script - run manually when needed
|
|
|
|
|
# Usage: ./restore.sh <backup_date>
|
|
|
|
|
# Example: ./restore.sh 20250117_030000
|
|
|
|
|
#
|
|
|
|
|
# Before restoring, enable maintenance mode:
|
|
|
|
|
# kubectl exec -n nextcloud deployment/nextcloud -- php occ maintenance:mode --on
|
|
|
|
|
# After restoring, disable it:
|
|
|
|
|
# kubectl exec -n nextcloud deployment/nextcloud -- php occ maintenance:mode --off
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
|
echo "Usage: $0 <backup_date>"
|
|
|
|
|
echo "Available backups:"
|
|
|
|
|
ls -1 /backup/
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
BACKUP_PATH="/backup/$1"
|
|
|
|
|
DATA_DIR="/nextcloud-data"
|
|
|
|
|
|
|
|
|
|
if [ ! -d "$BACKUP_PATH" ]; then
|
|
|
|
|
echo "Backup not found: $BACKUP_PATH"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Restoring from $BACKUP_PATH"
|
|
|
|
|
|
|
|
|
|
# Restore everything
|
|
|
|
|
echo "Restoring Nextcloud installation..."
|
|
|
|
|
rsync -a "$BACKUP_PATH/" "$DATA_DIR/"
|
|
|
|
|
|
|
|
|
|
echo "Restore completed!"
|
|
|
|
|
echo "Remember to run: kubectl exec -n nextcloud deployment/nextcloud -- php occ maintenance:mode --off"
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_cron_job_v1" "nextcloud-backup" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "nextcloud-backup"
|
|
|
|
|
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
schedule = "0 3 * * 0" # Sunday at 3 AM
|
|
|
|
|
successful_jobs_history_limit = 3
|
|
|
|
|
failed_jobs_history_limit = 3
|
|
|
|
|
concurrency_policy = "Forbid"
|
|
|
|
|
|
|
|
|
|
job_template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
|
|
|
|
template {
|
|
|
|
|
metadata {}
|
|
|
|
|
spec {
|
|
|
|
|
restart_policy = "OnFailure"
|
|
|
|
|
|
|
|
|
|
container {
|
|
|
|
|
name = "backup"
|
|
|
|
|
image = "alpine:latest"
|
|
|
|
|
|
|
|
|
|
command = ["/bin/sh", "-c", "apk add --no-cache rsync bash && /scripts/backup.sh"]
|
|
|
|
|
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "nextcloud-data"
|
|
|
|
|
mount_path = "/nextcloud-data"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "backup"
|
|
|
|
|
mount_path = "/backup"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "scripts"
|
|
|
|
|
mount_path = "/scripts"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume {
|
|
|
|
|
name = "nextcloud-data"
|
[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 {
|
2026-03-14 08:20:51 +00:00
|
|
|
claim_name = kubernetes_persistent_volume_claim.nextcloud_data_iscsi.metadata[0].name
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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_nextcloud_backup.claim_name
|
2026-02-22 15:13:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
volume {
|
|
|
|
|
name = "scripts"
|
|
|
|
|
config_map {
|
|
|
|
|
name = kubernetes_config_map.backup-script.metadata[0].name
|
|
|
|
|
default_mode = "0755"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-22 13:56:34 +00:00
|
|
|
}
|