diff --git a/ansible/host_vars/dev-01.lab.alexpires.me.yml b/ansible/host_vars/dev-01.lab.alexpires.me.yml index 6df81db..dac85ad 100644 --- a/ansible/host_vars/dev-01.lab.alexpires.me.yml +++ b/ansible/host_vars/dev-01.lab.alexpires.me.yml @@ -56,6 +56,7 @@ ufw_outgoing_traffic: - 8880 # Kokoro-FastAPI - 11434 # Ollama - 16443 # Kubernetes API + - 8188 # comfyui - 4443 - 9443 - 995 # POP3S diff --git a/terraform/apps/dev-01/apps.tf b/terraform/apps/dev-01/apps.tf index cd728d7..54c92f5 100644 --- a/terraform/apps/dev-01/apps.tf +++ b/terraform/apps/dev-01/apps.tf @@ -39,3 +39,11 @@ module "nextcloud" { tls_enabled = true issuer = local.internal_issuer } + +module "comfyui_proxy" { + source = "../../modules/apps/wol_proxy" + + upstream = local.comfyui_proxy + proxy_port = local.comfyui_proxy.port + namespace = "comfyui" +} \ No newline at end of file diff --git a/terraform/apps/dev-01/config.tf b/terraform/apps/dev-01/config.tf index cc34e68..ed3c3ef 100644 --- a/terraform/apps/dev-01/config.tf +++ b/terraform/apps/dev-01/config.tf @@ -87,8 +87,7 @@ locals { https_port = 8443 tls = true fqdn = ["comfyui.lab.alexpires.me"] - upstream = "http://comfyui-backend.lab.alexpires.me:8188" - resolver = "10.19.4.136" + upstream = "http://upstream.comfyui.svc.cluster.local:8188" locations = [ { @@ -109,13 +108,20 @@ locals { } ollama_proxy = { - enabled = true + enabled = true mac = "04:7c:16:d6:63:66" ip = "10.19.4.106" port = "11434" scheme = "http" } + comfyui_proxy = { + mac = "04:7c:16:d6:63:66" + ip = "10.19.4.106" + port = "8188" + scheme = "http" + } + scaleway_smtp_host = "smtp.tem.scw.cloud" nextcloud_fqdn = "cloud.alexpires.me" diff --git a/terraform/modules/apps/wol_proxy/ingress.tf b/terraform/modules/apps/wol_proxy/ingress.tf new file mode 100644 index 0000000..e3599c9 --- /dev/null +++ b/terraform/modules/apps/wol_proxy/ingress.tf @@ -0,0 +1,34 @@ +# resource "kubernetes_ingress_v1" "proxy" { +# metadata { +# name = "ingress" +# namespace = kubernetes_namespace.proxy.metadata[0].name + +# annotations = { +# "kubernetes.io/ingress.class" = "public" +# "cert-manager.io/cluster-issuer" = "letsencrypt-prod" +# "kubernetes.io/tls-acme" = "true" +# "nginx.ingress.kubernetes.io/ssl-redirect" = "true" +# } +# } +# spec { +# tls { +# hosts = [var.fqdn] +# secret_name = "proxy-tls" +# } +# rule { +# host = var.fqdn +# http { +# path { +# backend { +# service { +# name = "upstream" +# port { +# number = var.proxy_port +# } +# } +# } +# } +# } +# } +# } +# } diff --git a/terraform/modules/apps/wol_proxy/main.tf b/terraform/modules/apps/wol_proxy/main.tf new file mode 100644 index 0000000..5c48385 --- /dev/null +++ b/terraform/modules/apps/wol_proxy/main.tf @@ -0,0 +1,5 @@ +resource "kubernetes_namespace" "proxy" { + metadata { + name = var.namespace + } +} diff --git a/terraform/modules/apps/wol_proxy/provider.tf b/terraform/modules/apps/wol_proxy/provider.tf new file mode 100644 index 0000000..2eaa508 --- /dev/null +++ b/terraform/modules/apps/wol_proxy/provider.tf @@ -0,0 +1,9 @@ +terraform { + required_version = "~>1.8" + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + version = "2.36.0" + } + } +} diff --git a/terraform/modules/apps/wol_proxy/proxy.tf b/terraform/modules/apps/wol_proxy/proxy.tf new file mode 100644 index 0000000..2c203ac --- /dev/null +++ b/terraform/modules/apps/wol_proxy/proxy.tf @@ -0,0 +1,123 @@ +resource "kubernetes_service_account" "proxy" { + + metadata { + name = "wol-proxy-sa" + namespace = kubernetes_namespace.proxy.metadata[0].name + } + + automount_service_account_token = false +} + +resource "kubernetes_deployment" "proxy" { + + metadata { + name = "wol-proxy" + namespace = kubernetes_namespace.proxy.metadata[0].name + labels = { + app = "wol-proxy" + } + } + + spec { + replicas = 1 + selector { + match_labels = { + app = "wol-proxy" + } + } + + strategy { + type = "Recreate" + } + + template { + metadata { + labels = { + app = "wol-proxy" + } + } + + spec { + service_account_name = kubernetes_service_account.proxy.metadata[0].name + automount_service_account_token = false + + host_network = true + container { + name = "app" + image = "a13labs/wol_proxy:${var.tag}" + image_pull_policy = "Always" + + security_context { + capabilities { + add = ["NET_RAW"] + } + } + + port { + name = "upstream" + container_port = var.proxy_port + } + + env { + name = "UPSTREAM_MAC" + value = var.upstream.mac + } + + env { + name = "UPSTREAM_IP" + value = var.upstream.ip + } + + env { + name = "UPSTREAM_PORT" + value = var.upstream.port + } + + env { + name = "UPSTREAM_SCHEME" + value = var.upstream.scheme + } + + env { + name = "PROXY_PORT" + value = var.proxy_port + } + + readiness_probe { + tcp_socket { + port = var.proxy_port + } + initial_delay_seconds = 5 + period_seconds = 10 + failure_threshold = 10 + } + } + } + } + } +} + +resource "kubernetes_service" "proxy" { + metadata { + name = "upstream" + namespace = kubernetes_namespace.proxy.metadata[0].name + } + + spec { + selector = { + app = "proxy" + } + + port { + name = "upstream" + port = var.proxy_port + target_port = var.proxy_port + } + } + + lifecycle { + ignore_changes = [ + metadata[0].annotations + ] + } +} diff --git a/terraform/modules/apps/wol_proxy/variables.tf b/terraform/modules/apps/wol_proxy/variables.tf new file mode 100644 index 0000000..1088c1d --- /dev/null +++ b/terraform/modules/apps/wol_proxy/variables.tf @@ -0,0 +1,32 @@ +variable "upstream" { + description = "Configuration for the upstream proxy" + type = object({ + mac = optional(string, "") + ip = optional(string, "") + port = optional(string, "") + scheme = optional(string, "http") + }) +} + +# variable "fqdn" { +# description = "The fully qualified domain name for the app server" +# type = string +# } + +variable "tag" { + description = "The version of app to install" + type = string + default = "v0.4.0" +} + +variable "namespace" { + description = "The namespace for the proxy" + type = string + default = "wol-proxy" +} + +variable "proxy_port" { + description = "The port on which the proxy will listen" + type = number + default = 8080 +} \ No newline at end of file