Files
momentum-system/deploy/helm/momentum/templates/app-deployment.yaml
T
Claude e91979a622 Add Kubernetes image + Helm package with in-cluster Postgres
Containerizes the momentum monolith and packages every run mode for
deployment in a single Kubernetes namespace, with PostgreSQL hosted in
the cluster.

- Dockerfile (python:3.11-slim, non-root, writable /app/data) + .dockerignore
- GitHub Actions workflow publishing to ghcr.io/fez5587/momentum-system
- Helm chart (deploy/helm/momentum):
  * PostgreSQL StatefulSet + PVC (single source of truth; schema
    auto-creates from storage/pg_schema.sql on first connect)
  * App Deployment running run_live_paper.py with the embedded dashboard
    (replicas: 1, Recreate; the dashboard's write endpoints need the
    in-process TradingExecutionService) + Service/Ingress on 8010, plus a
    wait-for-postgres initContainer
  * CronJobs for journal / eod-replay / nightly-tune (US/Eastern via
    spec.timeZone) sharing the app data PVC
  * ConfigMap (tuning env) + Secret (DATABASE_URL/broker keys, existingSecret
    supported); DATABASE_URL built from the in-cluster Postgres service
  * Optional Grafana provisioned against the in-cluster Postgres
- deploy/README.md with install, secrets, and constraints

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JCVMm2AbmZvvxwLTX6UpNR
2026-06-19 17:22:06 +00:00

81 lines
2.9 KiB
YAML

apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "momentum.appName" . }}
labels:
{{- include "momentum.labels" . | nindent 4 }}
app.kubernetes.io/component: app
spec:
# Stateful singleton: the loop holds in-memory trading state and a 1:1 broker
# session. Never scale > 1. Recreate avoids two loops overlapping on rollout.
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
{{- include "momentum.selectorLabels" (dict "ctx" . "component" "app") | nindent 6 }}
template:
metadata:
labels:
{{- include "momentum.selectorLabels" (dict "ctx" . "component" "app") | nindent 8 }}
annotations:
# Roll the pod when config/secret content changes.
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
initContainers:
# Block until Postgres accepts connections so the first app connection
# (which auto-applies storage/pg_schema.sql) succeeds.
- name: wait-for-postgres
image: {{ .Values.postgres.image | quote }}
command:
- sh
- -c
- |
until pg_isready -h {{ include "momentum.postgresName" . }} -p {{ .Values.postgres.port }} -U {{ .Values.postgres.username }}; do
echo "waiting for postgres..."; sleep 2;
done
containers:
- name: app
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: {{ toYaml .Values.app.command | nindent 12 }}
ports:
- name: http
containerPort: 8010
envFrom:
- configMapRef:
name: {{ include "momentum.configMapName" . }}
- secretRef:
name: {{ include "momentum.secretName" . }}
volumeMounts:
- name: app-data
mountPath: /app/data
{{- if .Values.app.probes.enabled }}
readinessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: {{ .Values.app.probes.initialDelaySeconds }}
periodSeconds: {{ .Values.app.probes.periodSeconds }}
livenessProbe:
httpGet:
path: /
port: http
initialDelaySeconds: {{ .Values.app.probes.initialDelaySeconds }}
periodSeconds: {{ .Values.app.probes.periodSeconds }}
{{- end }}
resources:
{{- toYaml .Values.app.resources | nindent 12 }}
volumes:
- name: app-data
{{- if .Values.app.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ include "momentum.appDataPvcName" . }}
{{- else }}
emptyDir: {}
{{- end }}