Files
momentum-system/deploy/helm/momentum/templates/grafana.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

159 lines
4.9 KiB
YAML

{{- if .Values.grafana.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "momentum.grafanaName" . }}-provisioning
labels:
{{- include "momentum.labels" . | nindent 4 }}
data:
# Datasource points at the in-cluster Postgres service (not the old LAN IP).
datasource.yaml: |
apiVersion: 1
datasources:
- name: Momentum
uid: momentum_pg
type: postgres
access: proxy
url: {{ include "momentum.postgresName" . }}:{{ .Values.postgres.port }}
user: {{ .Values.postgres.username }}
jsonData:
database: {{ .Values.postgres.database }}
sslmode: disable
postgresVersion: 1600
secureJsonData:
# Resolved at runtime from the env var below so it always matches the
# password stored in the Secret (avoids re-deriving it here).
password: $POSTGRES_PASSWORD
isDefault: true
editable: true
provider.yaml: |
apiVersion: 1
providers:
- name: momentum
orgId: 1
type: file
disableDeletion: false
updateIntervalSeconds: 10
allowUiUpdates: true
options:
path: /etc/grafana/provisioning/dashboards
foldersFromFilesStructure: false
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "momentum.grafanaName" . }}-dashboards
labels:
{{- include "momentum.labels" . | nindent 4 }}
data:
momentum.json: |-
{{- .Files.Get "files/dashboard.json" | nindent 4 }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "momentum.grafanaName" . }}
labels:
{{- include "momentum.labels" . | nindent 4 }}
app.kubernetes.io/component: grafana
spec:
replicas: 1
selector:
matchLabels:
{{- include "momentum.selectorLabels" (dict "ctx" . "component" "grafana") | nindent 6 }}
template:
metadata:
labels:
{{- include "momentum.selectorLabels" (dict "ctx" . "component" "grafana") | nindent 8 }}
spec:
containers:
- name: grafana
image: {{ .Values.grafana.image | quote }}
ports:
- name: http
containerPort: 3000
env:
- name: GF_AUTH_ANONYMOUS_ENABLED
value: "true"
- name: GF_AUTH_ANONYMOUS_ORG_ROLE
value: "Admin"
- name: GF_AUTH_DISABLE_LOGIN_FORM
value: "true"
- name: GF_DASHBOARDS_MIN_REFRESH_INTERVAL
value: "2s"
# Interpolated into the provisioned datasource (secureJsonData.password).
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "momentum.secretName" . }}
key: POSTGRES_PASSWORD
volumeMounts:
- name: datasources
mountPath: /etc/grafana/provisioning/datasources
- name: dashboard-provider
mountPath: /etc/grafana/provisioning/dashboards/provider.yaml
subPath: provider.yaml
- name: dashboards
mountPath: /etc/grafana/provisioning/dashboards/momentum.json
subPath: momentum.json
- name: storage
mountPath: /var/lib/grafana
resources:
{{- toYaml .Values.grafana.resources | nindent 12 }}
volumes:
- name: datasources
configMap:
name: {{ include "momentum.grafanaName" . }}-provisioning
items:
- key: datasource.yaml
path: datasource.yaml
- name: dashboard-provider
configMap:
name: {{ include "momentum.grafanaName" . }}-provisioning
items:
- key: provider.yaml
path: provider.yaml
- name: dashboards
configMap:
name: {{ include "momentum.grafanaName" . }}-dashboards
- name: storage
{{- if .Values.grafana.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ include "momentum.grafanaName" . }}
{{- else }}
emptyDir: {}
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ include "momentum.grafanaName" . }}
labels:
{{- include "momentum.labels" . | nindent 4 }}
spec:
type: {{ .Values.grafana.service.type }}
selector:
{{- include "momentum.selectorLabels" (dict "ctx" . "component" "grafana") | nindent 4 }}
ports:
- name: http
port: {{ .Values.grafana.service.port }}
targetPort: http
{{- if .Values.grafana.persistence.enabled }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "momentum.grafanaName" . }}
labels:
{{- include "momentum.labels" . | nindent 4 }}
spec:
accessModes: ["ReadWriteOnce"]
{{- if .Values.grafana.persistence.storageClass }}
storageClassName: {{ .Values.grafana.persistence.storageClass | quote }}
{{- end }}
resources:
requests:
storage: {{ .Values.grafana.persistence.size | quote }}
{{- end }}
{{- end }}