2026-03-07 14:30:36 +00:00
|
|
|
variable "tls_secret_name" {
|
2026-03-14 08:51:45 +00:00
|
|
|
type = string
|
2026-03-07 14:30:36 +00:00
|
|
|
sensitive = true
|
|
|
|
|
}
|
2026-03-14 08:51:45 +00:00
|
|
|
variable "nfs_server" { type = string }
|
2026-02-22 13:56:34 +00:00
|
|
|
|
|
|
|
|
|
2026-02-22 15:13:55 +00:00
|
|
|
resource "kubernetes_namespace" "tor-proxy" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "tor-proxy"
|
|
|
|
|
labels = {
|
|
|
|
|
"istio-injection" : "disabled"
|
|
|
|
|
tier = local.tiers.aux
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "tls_secret" {
|
|
|
|
|
source = "../../modules/kubernetes/setup_tls_secret"
|
|
|
|
|
namespace = "tor-proxy"
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# resource "kubernetes_config_map" "tor_config" {
|
|
|
|
|
# metadata {
|
|
|
|
|
# name = "tor-config"
|
|
|
|
|
# namespace = "tor-proxy"
|
|
|
|
|
# annotations = {
|
|
|
|
|
# "reloader.stakater.com/match" = "true"
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
# data = {
|
|
|
|
|
# "torrc" = file("${path.module}/.torrc")
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_deployment" "tor-proxy" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "tor-proxy"
|
|
|
|
|
namespace = "tor-proxy"
|
|
|
|
|
labels = {
|
|
|
|
|
app = "tor-proxy"
|
|
|
|
|
tier = local.tiers.aux
|
|
|
|
|
}
|
|
|
|
|
annotations = {
|
|
|
|
|
"reloader.stakater.com/search" = "true"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1
|
|
|
|
|
strategy {
|
|
|
|
|
type = "RollingUpdate"
|
|
|
|
|
}
|
|
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
app = "tor-proxy"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
labels = {
|
|
|
|
|
app = "tor-proxy"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
container {
|
|
|
|
|
name = "tor-proxy"
|
|
|
|
|
image = "dperson/torproxy:latest"
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
container_port = 8118
|
|
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "tor"
|
|
|
|
|
container_port = 9050
|
|
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
[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
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
cpu = "10m"
|
|
|
|
|
memory = "64Mi"
|
|
|
|
|
}
|
|
|
|
|
limits = {
|
2026-03-15 00:03:59 +00:00
|
|
|
memory = "128Mi"
|
[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
|
|
|
}
|
|
|
|
|
}
|
2026-02-22 15:13:55 +00:00
|
|
|
# volume_mount {
|
|
|
|
|
# name = "tor-config"
|
|
|
|
|
# mount_path = "/etc/tor/torrc"
|
|
|
|
|
# sub_path = "torrc"
|
|
|
|
|
# }
|
|
|
|
|
}
|
|
|
|
|
# volume {
|
|
|
|
|
# name = "tor-config"
|
|
|
|
|
# config_map {
|
|
|
|
|
# name = kubernetes_config_map.tor_config.metadata[0].name
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "tor-proxy" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "tor-proxy"
|
|
|
|
|
namespace = "tor-proxy"
|
|
|
|
|
labels = {
|
|
|
|
|
"app" = "tor-proxy"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
app = "tor-proxy"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
port = 8118
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "tor"
|
|
|
|
|
port = 9050
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-22 13:56:34 +00:00
|
|
|
}
|
2026-03-14 08:51:45 +00:00
|
|
|
|
|
|
|
|
# --- TorrServer ---
|
|
|
|
|
|
|
|
|
|
module "nfs_torrserver_data" {
|
|
|
|
|
source = "../../modules/kubernetes/nfs_volume"
|
|
|
|
|
name = "tor-proxy-torrserver-data"
|
|
|
|
|
namespace = kubernetes_namespace.tor-proxy.metadata[0].name
|
|
|
|
|
nfs_server = var.nfs_server
|
|
|
|
|
nfs_path = "/mnt/main/tor-proxy/torrserver"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_deployment" "torrserver" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "torrserver"
|
|
|
|
|
namespace = kubernetes_namespace.tor-proxy.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
app = "torrserver"
|
|
|
|
|
tier = local.tiers.aux
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
replicas = 1
|
|
|
|
|
strategy {
|
|
|
|
|
type = "Recreate"
|
|
|
|
|
}
|
|
|
|
|
selector {
|
|
|
|
|
match_labels = {
|
|
|
|
|
app = "torrserver"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
template {
|
|
|
|
|
metadata {
|
|
|
|
|
labels = {
|
|
|
|
|
app = "torrserver"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
spec {
|
|
|
|
|
container {
|
|
|
|
|
name = "torrserver"
|
|
|
|
|
image = "ghcr.io/yourok/torrserver:MatriX.141"
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
container_port = 8090
|
|
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
|
|
|
|
resources {
|
|
|
|
|
requests = {
|
|
|
|
|
cpu = "100m"
|
|
|
|
|
memory = "256Mi"
|
|
|
|
|
}
|
|
|
|
|
limits = {
|
right-size memory: set requests=limits based on actual usage
- Set memory requests = limits across 56 stacks to prevent overcommit
- Right-sized limits based on actual pod usage (2x actual, rounded up)
- Scaled down trading-bot (replicas=0) to free memory
- Fixed OOMKilled services: forgejo, dawarich, health, meshcentral,
paperless-ngx, vault auto-unseal, rybbit, whisper, openclaw, clickhouse
- Added startup+liveness probes to calibre-web
- Bumped inotify limits on nodes 2,3 (max_user_instances 128->8192)
Post node2 OOM incident (2026-03-14). Previous kubelet config had no
kubeReserved/systemReserved set, allowing pods to starve the kernel.
2026-03-14 21:01:24 +00:00
|
|
|
memory = "256Mi"
|
2026-03-14 08:51:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
readiness_probe {
|
|
|
|
|
http_get {
|
|
|
|
|
path = "/echo"
|
|
|
|
|
port = 8090
|
|
|
|
|
}
|
|
|
|
|
initial_delay_seconds = 5
|
|
|
|
|
period_seconds = 10
|
|
|
|
|
}
|
|
|
|
|
liveness_probe {
|
|
|
|
|
http_get {
|
|
|
|
|
path = "/echo"
|
|
|
|
|
port = 8090
|
|
|
|
|
}
|
|
|
|
|
initial_delay_seconds = 15
|
|
|
|
|
period_seconds = 30
|
|
|
|
|
}
|
|
|
|
|
volume_mount {
|
|
|
|
|
name = "torrserver-data"
|
|
|
|
|
mount_path = "/opt/ts"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
volume {
|
|
|
|
|
name = "torrserver-data"
|
|
|
|
|
persistent_volume_claim {
|
|
|
|
|
claim_name = module.nfs_torrserver_data.claim_name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "kubernetes_service" "torrserver" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "torrserver"
|
|
|
|
|
namespace = kubernetes_namespace.tor-proxy.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
"app" = "torrserver"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
selector = {
|
|
|
|
|
app = "torrserver"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "http"
|
|
|
|
|
port = 8090
|
|
|
|
|
target_port = 8090
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Expose BT peer port for better torrent connectivity
|
|
|
|
|
resource "kubernetes_service" "torrserver-bt" {
|
|
|
|
|
metadata {
|
|
|
|
|
name = "torrserver-bt"
|
|
|
|
|
namespace = kubernetes_namespace.tor-proxy.metadata[0].name
|
|
|
|
|
labels = {
|
|
|
|
|
app = "torrserver-bt"
|
|
|
|
|
}
|
|
|
|
|
annotations = {
|
|
|
|
|
"metallb.universe.tf/allow-shared-ip" = "shared"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spec {
|
|
|
|
|
type = "LoadBalancer"
|
|
|
|
|
external_traffic_policy = "Cluster"
|
|
|
|
|
selector = {
|
|
|
|
|
app = "torrserver"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "bt-tcp"
|
|
|
|
|
port = 5665
|
|
|
|
|
target_port = 5665
|
|
|
|
|
protocol = "TCP"
|
|
|
|
|
}
|
|
|
|
|
port {
|
|
|
|
|
name = "bt-udp"
|
|
|
|
|
port = 5665
|
|
|
|
|
target_port = 5665
|
|
|
|
|
protocol = "UDP"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module "torrserver_ingress" {
|
|
|
|
|
source = "../../modules/kubernetes/ingress_factory"
|
|
|
|
|
namespace = kubernetes_namespace.tor-proxy.metadata[0].name
|
|
|
|
|
name = "torrserver"
|
|
|
|
|
tls_secret_name = var.tls_secret_name
|
|
|
|
|
port = "8090"
|
|
|
|
|
protected = true
|
|
|
|
|
extra_annotations = {
|
|
|
|
|
"gethomepage.dev/enabled" = "true"
|
|
|
|
|
"gethomepage.dev/name" = "TorrServer"
|
|
|
|
|
"gethomepage.dev/description" = "Torrent streaming server"
|
|
|
|
|
"gethomepage.dev/icon" = "torrserver.png"
|
|
|
|
|
"gethomepage.dev/group" = "Media & Entertainment"
|
|
|
|
|
"gethomepage.dev/pod-selector" = ""
|
|
|
|
|
}
|
|
|
|
|
}
|