From eb7b57aa4233379ff55e53795a3b6e951b619fb4 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 17 Jan 2026 16:30:38 -0600 Subject: [PATCH] feat: add Valkey as k8s sidecar for Redis compatibility - Add Valkey 8.0 alpine container as sidecar in k8s deployment - Configure with appropriate security context (non-root, no privilege escalation) - Add resource limits (256Mi memory, 200m CPU) and requests (128Mi, 50m) - Add health probes using valkey-cli ping command - Configure Redis connection via REDIS_HOST and REDIS_PORT environment variables - Add Redis config to runtime.exs, dev.exs, and test.exs - Valkey runs on localhost:6379 within the same pod as Phoenix app --- config/dev.exs | 5 +++++ config/runtime.exs | 8 ++++++++ config/test.exs | 5 +++++ k8s/deployment.yaml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/config/dev.exs b/config/dev.exs index 73c195d1..f75ac8d1 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -92,5 +92,10 @@ config :towerops, ToweropsWeb.Endpoint, ] ] +# Configure Redis/Valkey for development +config :towerops, :redis, + host: "localhost", + port: 6379 + # Enable dev routes for dashboard and mailbox config :towerops, dev_routes: true diff --git a/config/runtime.exs b/config/runtime.exs index 2b0a91da..00045bd7 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -46,6 +46,10 @@ if config_env() == :prod do host = System.get_env("PHX_HOST") || "example.com" + # Configure Redis/Valkey connection + redis_host = System.get_env("REDIS_HOST") || "localhost" + redis_port = String.to_integer(System.get_env("REDIS_PORT") || "6379") + config :libcluster, topologies: [ k8s: [ @@ -147,4 +151,8 @@ if config_env() == :prod do # Set default sender for all emails config :towerops, :mailer_from, {"Towerops", "hi@towerops.net"} + + config :towerops, :redis, + host: redis_host, + port: redis_port end diff --git a/config/test.exs b/config/test.exs index fb0ae1d4..5413f22f 100644 --- a/config/test.exs +++ b/config/test.exs @@ -46,6 +46,11 @@ config :towerops, ToweropsWeb.Endpoint, # Set environment identifier for runtime checks config :towerops, :env, :test +# Configure Redis/Valkey for testing +config :towerops, :redis, + host: "localhost", + port: 6379 + # Use mocks for testing config :towerops, ping_module: Towerops.Monitoring.PingMock, diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml index 54186ab2..2591f15b 100644 --- a/k8s/deployment.yaml +++ b/k8s/deployment.yaml @@ -84,6 +84,10 @@ spec: secretKeyRef: name: towerops-secrets key: SECRET_KEY_BASE + - name: REDIS_HOST + value: "localhost" + - name: REDIS_PORT + value: "6379" envFrom: - secretRef: name: towerops-db @@ -113,3 +117,44 @@ spec: timeoutSeconds: 2 successThreshold: 1 failureThreshold: 2 + - name: valkey + image: valkey/valkey:8.0-alpine + imagePullPolicy: IfNotPresent + securityContext: + allowPrivilegeEscalation: false + runAsNonRoot: true + runAsUser: 999 + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + ports: + - containerPort: 6379 + name: valkey + resources: + requests: + memory: "128Mi" + cpu: "50m" + limits: + memory: "256Mi" + cpu: "200m" + livenessProbe: + exec: + command: + - valkey-cli + - ping + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 2 + failureThreshold: 3 + readinessProbe: + exec: + command: + - valkey-cli + - ping + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 2 + successThreshold: 1 + failureThreshold: 2