infra/stacks/freedify/factory/main.tf
Viktor Barzin 9e4fb23b10 [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

149 lines
2.9 KiB
HCL
Executable file

variable "tls_secret_name" {}
variable "name" {}
variable "tag" {
default = "latest"
}
variable "tier" { type = string }
variable "protected" {
type = bool
default = false
}
variable "listenbrainz_token" {
type = string
default = null
}
variable "genius_token" {
type = string
default = null
}
variable "dab_visitor_id" {
type = string
default = null
}
variable "dab_session" {
type = string
default = null
}
variable "gemini_api_key" {
type = string
default = null
}
variable "cpu_limit" {
type = string
default = "250m"
}
variable "memory_limit" {
type = string
default = "256Mi"
}
variable "cpu_request" {
type = string
default = "15m"
}
variable "memory_request" {
type = string
default = "64Mi"
}
resource "kubernetes_deployment" "freedify" {
metadata {
name = "music-${var.name}"
namespace = "freedify"
labels = {
app = "music-${var.name}"
tier = var.tier
}
}
spec {
replicas = 1
strategy {
type = "RollingUpdate"
}
selector {
match_labels = {
app = "music-${var.name}"
}
}
template {
metadata {
annotations = {
"diun.enable" = "true"
"diun.include_tags" = "^${var.tag}$"
}
labels = {
app = "music-${var.name}"
}
}
spec {
container {
image = "viktorbarzin/freedify:${var.tag}"
name = "freedify"
port {
container_port = 8000
}
env {
name = "LISTENBRAINZ_TOKEN"
value = var.listenbrainz_token
}
env {
name = "GENIUS_ACCESS_TOKEN"
value = var.genius_token
}
env {
name = "DAB_SESSION"
value = var.dab_session
}
env {
name = "DAB_VISITOR_ID"
value = var.dab_visitor_id
}
env {
name = "GEMINI_API_KEY"
value = var.gemini_api_key
}
resources {
limits = {
cpu = var.cpu_limit
memory = var.memory_limit
}
requests = {
cpu = var.cpu_request
memory = var.memory_request
}
}
}
}
}
}
}
resource "kubernetes_service" "freedify" {
metadata {
name = "music-${var.name}"
namespace = "freedify"
labels = {
app = "music-${var.name}"
}
}
spec {
selector = {
app = "music-${var.name}"
}
port {
name = "http"
port = 80
target_port = 8000
}
}
}
module "ingress" {
source = "../../../modules/kubernetes/ingress_factory"
namespace = "freedify"
name = "music-${var.name}"
tls_secret_name = var.tls_secret_name
protected = var.protected
}