infra/stacks/whisper/main.tf
Viktor Barzin ca648ff9bb
[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

280 lines
5.6 KiB
HCL

variable "tls_secret_name" { type = string }
variable "nfs_server" { type = string }
resource "kubernetes_namespace" "whisper" {
metadata {
name = "whisper"
labels = {
tier = local.tiers.gpu
}
}
}
module "tls_secret" {
source = "../../modules/kubernetes/setup_tls_secret"
namespace = kubernetes_namespace.whisper.metadata[0].name
tls_secret_name = var.tls_secret_name
}
resource "kubernetes_deployment" "whisper" {
metadata {
name = "whisper"
namespace = kubernetes_namespace.whisper.metadata[0].name
labels = {
app = "whisper"
tier = local.tiers.gpu
}
}
spec {
replicas = 1
strategy {
type = "Recreate"
}
selector {
match_labels = {
app = "whisper"
}
}
template {
metadata {
labels = {
app = "whisper"
}
}
spec {
node_selector = {
"gpu" : "true"
}
toleration {
key = "nvidia.com/gpu"
operator = "Equal"
value = "true"
effect = "NoSchedule"
}
container {
name = "whisper"
image = "rhasspy/wyoming-whisper:latest"
args = ["--model", "small-int8", "--language", "en", "--beam-size", "1"]
port {
container_port = 10300
protocol = "TCP"
}
volume_mount {
name = "data"
mount_path = "/data"
}
resources {
requests = {
cpu = "25m"
memory = "256Mi"
}
limits = {
cpu = "500m"
memory = "1536Mi"
}
}
}
volume {
name = "data"
nfs {
server = var.nfs_server
path = "/mnt/main/whisper"
}
}
}
}
}
}
resource "kubernetes_service" "whisper" {
metadata {
name = "whisper"
namespace = kubernetes_namespace.whisper.metadata[0].name
labels = {
app = "whisper"
}
}
spec {
selector = {
app = "whisper"
}
port {
name = "wyoming"
port = 10300
target_port = 10300
protocol = "TCP"
}
}
}
# TCP passthrough from Traefik to whisper service
resource "kubernetes_manifest" "whisper_tcp_ingressroute" {
manifest = {
apiVersion = "traefik.io/v1alpha1"
kind = "IngressRouteTCP"
metadata = {
name = "whisper-tcp"
namespace = "traefik"
}
spec = {
entryPoints = ["whisper-tcp"]
routes = [{
match = "HostSNI(`*`)"
services = [{
name = "whisper"
namespace = "whisper"
port = 10300
}]
}]
}
}
}
# Piper TTS
resource "kubernetes_deployment" "piper" {
metadata {
name = "piper"
namespace = kubernetes_namespace.whisper.metadata[0].name
labels = {
app = "piper"
tier = local.tiers.gpu
}
}
spec {
replicas = 1
strategy {
type = "Recreate"
}
selector {
match_labels = {
app = "piper"
}
}
template {
metadata {
labels = {
app = "piper"
}
}
spec {
node_selector = {
"gpu" : "true"
}
toleration {
key = "nvidia.com/gpu"
operator = "Equal"
value = "true"
effect = "NoSchedule"
}
container {
name = "piper"
image = "rhasspy/wyoming-piper:latest"
args = ["--voice", "en_US-lessac-medium"]
port {
container_port = 10200
protocol = "TCP"
}
volume_mount {
name = "data"
mount_path = "/data"
}
resources {
requests = {
cpu = "25m"
memory = "64Mi"
}
limits = {
cpu = "250m"
memory = "512Mi"
}
}
}
volume {
name = "data"
nfs {
server = var.nfs_server
path = "/mnt/main/whisper"
}
}
}
}
}
}
resource "kubernetes_service" "piper" {
metadata {
name = "piper"
namespace = kubernetes_namespace.whisper.metadata[0].name
labels = {
app = "piper"
}
}
spec {
selector = {
app = "piper"
}
port {
name = "wyoming"
port = 10200
target_port = 10200
protocol = "TCP"
}
}
}
# TCP passthrough from Traefik to piper service
resource "kubernetes_manifest" "piper_tcp_ingressroute" {
manifest = {
apiVersion = "traefik.io/v1alpha1"
kind = "IngressRouteTCP"
metadata = {
name = "piper-tcp"
namespace = "traefik"
}
spec = {
entryPoints = ["piper-tcp"]
routes = [{
match = "HostSNI(`*`)"
services = [{
name = "piper"
namespace = "whisper"
port = 10200
}]
}]
}
}
}
# TCP passthrough from Traefik to ollama service (for HA voice pipeline)
resource "kubernetes_manifest" "ollama_tcp_ingressroute" {
manifest = {
apiVersion = "traefik.io/v1alpha1"
kind = "IngressRouteTCP"
metadata = {
name = "ollama-tcp"
namespace = "traefik"
}
spec = {
entryPoints = ["ollama-tcp"]
routes = [{
match = "HostSNI(`*`)"
services = [{
name = "ollama"
namespace = "ollama"
port = 11434
}]
}]
}
}
}