## Context Grampsweb stack had an empty Terraform state — 7 K8s resources (namespace, PVC, service, deployment, ingress, ExternalSecret manifest, TLS secret) existed in the cluster but weren't tracked. This blocked commit7b248897(ollama LLM env-var removal) from being applied because any apply would attempt to re-create existing resources. Additionally, the TF source declared a **grampsweb-data-proxmox** PVC on **storage_class=proxmox-lvm**, while the cluster had **grampsweb-data-encrypted** on **proxmox-lvm-encrypted** (1 Gi, bound). The deployment was referencing the encrypted PVC. This divergence predated this change — the source was simply out of date vs cluster reality. ## This change Two things: 1. **Source alignment** (the only file diff): - Renames `kubernetes_persistent_volume_claim.data_proxmox` → `data_encrypted`, metadata.name to match cluster, storage class to `proxmox-lvm-encrypted`. - Updates the deployment volume `claim_name` reference accordingly. - Aligns with the newer project convention documented in `.claude/CLAUDE.md`: "Default for sensitive data is proxmox-lvm-encrypted" and "Convention: PVC names end in `-encrypted`". - No destroy/recreate: the PVC and deployment already use the encrypted PVC in the cluster; TF source now just describes reality. 2. **State imports** (out-of-band, via `scripts/tg import`, not in diff): - `kubernetes_namespace.grampsweb` <- `grampsweb` - `kubernetes_persistent_volume_claim.data_encrypted` <- `grampsweb/grampsweb-data-encrypted` - `kubernetes_service.grampsweb` <- `grampsweb/grampsweb` - `kubernetes_deployment.grampsweb` <- `grampsweb/grampsweb` - `module.ingress.kubernetes_ingress_v1.proxied-ingress` <- `grampsweb/family` - `module.tls_secret.kubernetes_secret.tls_secret` <- `grampsweb/tls-secret` - `kubernetes_manifest.external_secret` <- `apiVersion=external-secrets.io/v1beta1,kind=ExternalSecret,namespace=grampsweb,name=grampsweb-secrets` ## Apply result `Apply complete! Resources: 0 added, 7 changed, 0 destroyed.` In-place updates applied: - Deployment: dropped `GRAMPSWEB_LLM_BASE_URL` + `GRAMPSWEB_LLM_MODEL` env vars (both containers) — realising the intent of commit7b248897. - Ingress: realigned Traefik middleware annotation + cleaned stale `uptime.viktorbarzin.me/external-monitor=false` annotation. - TLS secret: removed Kyverno-generated labels (Kyverno's `sync-tls-secret` ClusterPolicy re-applies them on next reconcile — no functional impact; same pattern in 29 other stacks using `setup_tls_secret` module). - Namespace, PVC, service: trivial metadata alignments (label / `wait_until_bound` / `wait_for_load_balancer`). - `kubernetes_manifest.external_secret`: populated the `manifest` attribute after import (expected). ## What is NOT in this change - No replica bump: deployment stays at `replicas=0` (stack is intentionally inactive per 2026-03-14 OOM incident note). - No destroy/recreate of any resource. - The broader code-w97 (11 stacks with empty state) is NOT closed — only grampsweb is imported. 10 stacks remain: beads-server, insta2spotify, isponsorblocktv, kyverno, meshcentral, pvc-autoresizer, shadowsocks, tor-proxy, travel_blog, + meshcentral PVC. ## Reproduce locally ``` KUBECONFIG=/home/wizard/code/config kubectl get all,ingress,pvc,externalsecret,secret -n grampsweb # Deployment still replicas=0; PVC grampsweb-data-encrypted Bound; ingress 'family' # on family.viktorbarzin.me; ExternalSecret SecretSynced True. cd /home/wizard/code/infra/stacks/grampsweb /home/wizard/code/infra/scripts/tg plan # Expected: 'No changes.' (clean state after apply). ``` ## Test Plan ### Automated ``` $ cd /home/wizard/code/infra/stacks/grampsweb && /home/wizard/code/infra/scripts/tg plan Plan: 0 to add, 7 to change, 0 to destroy. [pre-apply] $ /home/wizard/code/infra/scripts/tg apply --non-interactive Plan: 0 to add, 7 to change, 0 to destroy. kubernetes_namespace.grampsweb: Modifications complete after 0s [id=grampsweb] kubernetes_persistent_volume_claim.data_encrypted: Modifications complete after 0s [id=grampsweb/grampsweb-data-encrypted] kubernetes_service.grampsweb: Modifications complete after 0s [id=grampsweb/grampsweb] module.ingress.kubernetes_ingress_v1.proxied-ingress: Modifications complete after 0s [id=grampsweb/family] module.tls_secret.kubernetes_secret.tls_secret: Modifications complete after 0s [id=grampsweb/tls-secret] kubernetes_manifest.external_secret: Modifications complete after 0s kubernetes_deployment.grampsweb: Modifications complete after 1s [id=grampsweb/grampsweb] Apply complete! Resources: 0 added, 7 changed, 0 destroyed. $ terraform fmt -check -recursive stacks/grampsweb (no output - formatted clean) ``` ### Manual Verification ``` $ KUBECONFIG=/home/wizard/code/config kubectl get all,ingress,pvc,externalsecret,secret -n grampsweb # - deployment.apps/grampsweb 0/0 0 0 47d (replicas=0 preserved) # - service/grampsweb ClusterIP 10.106.232.205:80/TCP # - persistentvolumeclaim/grampsweb-data-encrypted Bound pvc-c9a5dcf4... 1Gi RWO proxmox-lvm-encrypted # - ingress/family traefik family.viktorbarzin.me -> 10.0.20.200:80,443 # - externalsecret/grampsweb-secrets vault-kv 15m SecretSynced True # - secret/tls-secret kubernetes.io/tls # No pod crashes (no pods — replicas=0). ``` Closes: code-8m6
364 lines
8.7 KiB
HCL
364 lines
8.7 KiB
HCL
variable "tls_secret_name" {
|
|
type = string
|
|
sensitive = true
|
|
}
|
|
variable "nfs_server" { type = string }
|
|
|
|
resource "kubernetes_manifest" "external_secret" {
|
|
manifest = {
|
|
apiVersion = "external-secrets.io/v1beta1"
|
|
kind = "ExternalSecret"
|
|
metadata = {
|
|
name = "grampsweb-secrets"
|
|
namespace = "grampsweb"
|
|
}
|
|
spec = {
|
|
refreshInterval = "15m"
|
|
secretStoreRef = {
|
|
name = "vault-kv"
|
|
kind = "ClusterSecretStore"
|
|
}
|
|
target = {
|
|
name = "grampsweb-secrets"
|
|
}
|
|
dataFrom = [{
|
|
extract = {
|
|
key = "grampsweb"
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
depends_on = [kubernetes_namespace.grampsweb]
|
|
}
|
|
|
|
data "kubernetes_secret" "eso_secrets" {
|
|
metadata {
|
|
name = "grampsweb-secrets"
|
|
namespace = kubernetes_namespace.grampsweb.metadata[0].name
|
|
}
|
|
depends_on = [kubernetes_manifest.external_secret]
|
|
}
|
|
|
|
locals {
|
|
mailserver_accounts = jsondecode(data.kubernetes_secret.eso_secrets.data["mailserver_accounts"])
|
|
}
|
|
variable "redis_host" { type = string }
|
|
variable "mail_host" { type = string }
|
|
|
|
|
|
resource "kubernetes_namespace" "grampsweb" {
|
|
metadata {
|
|
name = "grampsweb"
|
|
labels = {
|
|
tier = local.tiers.aux
|
|
}
|
|
}
|
|
}
|
|
|
|
module "tls_secret" {
|
|
source = "../../modules/kubernetes/setup_tls_secret"
|
|
namespace = kubernetes_namespace.grampsweb.metadata[0].name
|
|
tls_secret_name = var.tls_secret_name
|
|
}
|
|
|
|
resource "kubernetes_persistent_volume_claim" "data_encrypted" {
|
|
wait_until_bound = false
|
|
metadata {
|
|
name = "grampsweb-data-encrypted"
|
|
namespace = kubernetes_namespace.grampsweb.metadata[0].name
|
|
annotations = {
|
|
"resize.topolvm.io/threshold" = "80%"
|
|
"resize.topolvm.io/increase" = "100%"
|
|
"resize.topolvm.io/storage_limit" = "5Gi"
|
|
}
|
|
}
|
|
spec {
|
|
access_modes = ["ReadWriteOnce"]
|
|
storage_class_name = "proxmox-lvm-encrypted"
|
|
resources {
|
|
requests = {
|
|
storage = "1Gi"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "random_password" "secret_key" {
|
|
length = 64
|
|
special = false
|
|
}
|
|
|
|
locals {
|
|
common_env = [
|
|
{
|
|
name = "GRAMPSWEB_TREE"
|
|
value = "Gramps Web"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_SECRET_KEY"
|
|
value = random_password.secret_key.result
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_CELERY_CONFIG__broker_url"
|
|
value = "redis://${var.redis_host}:6379/2"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_CELERY_CONFIG__result_backend"
|
|
value = "redis://${var.redis_host}:6379/2"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_RATELIMIT_STORAGE_URI"
|
|
value = "redis://${var.redis_host}:6379/3"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_BASE_URL"
|
|
value = "https://family.viktorbarzin.me"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_REGISTRATION_DISABLED"
|
|
value = "True"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_EMAIL_HOST"
|
|
value = var.mail_host
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_EMAIL_PORT"
|
|
value = "587"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_EMAIL_HOST_USER"
|
|
value = "info@viktorbarzin.me"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_EMAIL_HOST_PASSWORD"
|
|
value = local.mailserver_accounts["info@viktorbarzin.me"]
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_EMAIL_USE_SSL"
|
|
value = "False"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_EMAIL_USE_STARTTLS"
|
|
value = "True"
|
|
},
|
|
{
|
|
name = "GRAMPSWEB_DEFAULT_FROM_EMAIL"
|
|
value = "info@viktorbarzin.me"
|
|
},
|
|
]
|
|
}
|
|
|
|
resource "kubernetes_deployment" "grampsweb" {
|
|
metadata {
|
|
name = "grampsweb"
|
|
namespace = kubernetes_namespace.grampsweb.metadata[0].name
|
|
labels = {
|
|
app = "grampsweb"
|
|
tier = local.tiers.aux
|
|
}
|
|
}
|
|
spec {
|
|
# Disabled: grampsweb uses ~1.8GB actual memory with 3GB limit per replica.
|
|
# Not actively used — disabled to reduce cluster memory pressure (2026-03-14 node2 OOM incident).
|
|
replicas = 0
|
|
strategy {
|
|
type = "Recreate"
|
|
}
|
|
selector {
|
|
match_labels = {
|
|
app = "grampsweb"
|
|
}
|
|
}
|
|
template {
|
|
metadata {
|
|
labels = {
|
|
app = "grampsweb"
|
|
}
|
|
annotations = {
|
|
"dependency.kyverno.io/wait-for" = "redis.redis:6379"
|
|
}
|
|
}
|
|
spec {
|
|
container {
|
|
name = "grampsweb"
|
|
image = "ghcr.io/gramps-project/grampsweb:latest"
|
|
|
|
port {
|
|
container_port = 5000
|
|
}
|
|
|
|
dynamic "env" {
|
|
for_each = local.common_env
|
|
content {
|
|
name = env.value.name
|
|
value = env.value.value
|
|
}
|
|
}
|
|
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/users"
|
|
sub_path = "users"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/indexdir"
|
|
sub_path = "indexdir"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/thumbnail_cache"
|
|
sub_path = "thumbnail_cache"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/cache"
|
|
sub_path = "cache"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/secret"
|
|
sub_path = "secret"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/root/.gramps/grampsdb"
|
|
sub_path = "grampsdb"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/media"
|
|
sub_path = "media"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/tmp"
|
|
sub_path = "tmp"
|
|
}
|
|
|
|
resources {
|
|
requests = {
|
|
cpu = "50m"
|
|
memory = "512Mi"
|
|
}
|
|
limits = {
|
|
memory = "512Mi"
|
|
}
|
|
}
|
|
}
|
|
|
|
container {
|
|
name = "grampsweb-celery"
|
|
image = "ghcr.io/gramps-project/grampsweb:latest"
|
|
command = ["celery", "-A", "gramps_webapi.celery", "worker", "--loglevel=INFO", "--concurrency=2"]
|
|
|
|
dynamic "env" {
|
|
for_each = local.common_env
|
|
content {
|
|
name = env.value.name
|
|
value = env.value.value
|
|
}
|
|
}
|
|
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/users"
|
|
sub_path = "users"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/indexdir"
|
|
sub_path = "indexdir"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/thumbnail_cache"
|
|
sub_path = "thumbnail_cache"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/cache"
|
|
sub_path = "cache"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/secret"
|
|
sub_path = "secret"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/root/.gramps/grampsdb"
|
|
sub_path = "grampsdb"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/app/media"
|
|
sub_path = "media"
|
|
}
|
|
volume_mount {
|
|
name = "data"
|
|
mount_path = "/tmp"
|
|
sub_path = "tmp"
|
|
}
|
|
|
|
resources {
|
|
requests = {
|
|
cpu = "50m"
|
|
memory = "256Mi"
|
|
}
|
|
limits = {
|
|
memory = "256Mi"
|
|
}
|
|
}
|
|
}
|
|
|
|
volume {
|
|
name = "data"
|
|
persistent_volume_claim {
|
|
claim_name = kubernetes_persistent_volume_claim.data_encrypted.metadata[0].name
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "kubernetes_service" "grampsweb" {
|
|
metadata {
|
|
name = "grampsweb"
|
|
namespace = kubernetes_namespace.grampsweb.metadata[0].name
|
|
labels = {
|
|
app = "grampsweb"
|
|
}
|
|
}
|
|
|
|
spec {
|
|
selector = {
|
|
app = "grampsweb"
|
|
}
|
|
port {
|
|
name = "http"
|
|
port = 80
|
|
target_port = 5000
|
|
}
|
|
}
|
|
}
|
|
|
|
module "ingress" {
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
namespace = kubernetes_namespace.grampsweb.metadata[0].name
|
|
name = "family"
|
|
service_name = "grampsweb"
|
|
tls_secret_name = var.tls_secret_name
|
|
max_body_size = "500m"
|
|
protected = true
|
|
extra_annotations = {
|
|
"gethomepage.dev/enabled" = "true"
|
|
"gethomepage.dev/name" = "GrampsWeb"
|
|
"gethomepage.dev/description" = "Family tree"
|
|
"gethomepage.dev/icon" = "gramps-web.png"
|
|
"gethomepage.dev/group" = "Other"
|
|
"gethomepage.dev/pod-selector" = ""
|
|
}
|
|
}
|