infra/clusters/aprs/aprs-statefulset-enhanced.yaml
2025-07-27 11:35:59 -05:00

132 lines
No EOL
4.2 KiB
YAML

apiVersion: apps/v1
kind: StatefulSet
metadata:
name: aprs
namespace: aprs
spec:
serviceName: aprs-headless
replicas: 2
selector:
matchLabels:
app: aprs
updateStrategy:
type: RollingUpdate
podManagementPolicy: Parallel
template:
metadata:
labels:
app: aprs
spec:
terminationGracePeriodSeconds: 60
initContainers:
- name: wait-for-db
image: busybox:1.36.1
command: ['sh', '-c', 'until nc -z pgbouncer 5432; do echo waiting for database; sleep 2; done']
- name: wait-for-redis
image: busybox:1.36.1
command: ['sh', '-c', 'until nc -z redis 6379; do echo waiting for redis; sleep 2; done']
containers:
- name: aprs
image: ghcr.io/aprsme/aprs.me:latest
imagePullPolicy: Always
ports:
- containerPort: 4000
protocol: TCP
env:
- name: SECRET_KEY_BASE
valueFrom:
secretKeyRef:
name: aprs-secret
key: secret-key-base
- name: DATABASE_URL
value: "ecto://aprs:$(DATABASE_PASSWORD)@pgbouncer:5432/aprs"
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: aprs-secret
key: database-password
- name: PHX_HOST
value: "aprs.me"
- name: PHX_SERVER
value: "true"
- name: POOL_SIZE
value: "5" # Reduced from default 10 to prevent connection exhaustion
- name: ECTO_IPV6
value: "false"
- name: ERLANG_COOKIE
valueFrom:
secretKeyRef:
name: aprs-secret
key: erlang-cookie
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: REDIS_URL
value: "redis://redis.aprs.svc.cluster.local:6379"
- name: DRAIN_TIMEOUT_MS
value: "45000"
- name: SKIP_DB_CREATE
value: "true"
# Enhanced database connection settings
- name: DATABASE_POOL_TIMEOUT
value: "60000" # 60 seconds
- name: DATABASE_QUEUE_TARGET
value: "50"
- name: DATABASE_QUEUE_INTERVAL
value: "1000"
- name: DATABASE_CONNECT_TIMEOUT
value: "30000" # 30 seconds
- name: DATABASE_IDLE_TIMEOUT
value: "900000" # 15 minutes
# Memory management
- name: ERL_MAX_ETS_TABLES
value: "5000"
- name: ERLANG_SCHEDULER_BUSY_WAIT_THRESHOLD
value: "none"
resources:
limits:
memory: "1Gi" # Increased from 512Mi
cpu: "1000m" # Increased from 500m
requests:
memory: "512Mi" # Increased from 256Mi
cpu: "500m" # Increased from 250m
livenessProbe:
httpGet:
path: /health
port: 4000
initialDelaySeconds: 60 # Increased from 30
periodSeconds: 10
timeoutSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /health
port: 4000
initialDelaySeconds: 30 # Increased from 5
periodSeconds: 5
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
startupProbe:
httpGet:
path: /health
port: 4000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 10
failureThreshold: 12 # 120 seconds total
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 15"]
imagePullSecrets:
- name: ghcr-pull-secret