Loading page
The manifests in deploy/k8s, read from this repository. A reference layout for a larger pipeline follows below.
kubectl create secret generic tommiebot-secrets --from-env-file=.env
kubectl apply -k deploy/k8s/base
kubectl apply -k deploy/k8s/overlays/components
kubectl apply -k deploy/k8s/overlays/dev
kubectl apply -k deploy/k8s/overlays/hybrid
kubectl apply -k deploy/k8s/overlays/llm-d
kubectl apply -k deploy/k8s/overlays/on-prem
kubectl apply -k deploy/k8s/overlays/productionapiVersion: v1
kind: ConfigMap
metadata:
name: tommiebot-config
data:
NODE_ENV: production
# Empty = AI Gateway only. The llm-d component points this at the in-cluster inference gateway.
LOCAL_LLM_BASE_URL: ""
LOCAL_LLM_ALLOW_REMOTE: "false"
# Empty = Neon over HTTPS (DATABASE_URL in tommiebot-secrets). The in-cluster-postgres component sets the /sql proxy.
DATABASE_HTTP_ENDPOINT: ""
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tommiebot
labels: { app: tommiebot, app.kubernetes.io/name: tommiebot, app.kubernetes.io/component: web }
spec:
replicas: 2
revisionHistoryLimit: 5
selector:
matchLabels: { app: tommiebot }
strategy:
type: RollingUpdate
rollingUpdate: { maxSurge: 1, maxUnavailable: 0 }
template:
metadata:
labels: { app: tommiebot, app.kubernetes.io/name: tommiebot, app.kubernetes.io/component: web, tommiebot/db-client: "true" }
spec:
serviceAccountName: tommiebot
automountServiceAccountToken: false
terminationGracePeriodSeconds: 30
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
fsGroup: 1001
seccompProfile: { type: RuntimeDefault }
# Spread replicas over nodes and zones when the cluster has them; never block scheduling on it.
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector: { matchLabels: { app: tommiebot } }
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: ScheduleAnyway
labelSelector: { matchLabels: { app: tommiebot } }
initContainers:
# The root filesystem is read-only, but the file-backed stores write under .specify/ (flags, quiz, blocks,
# ontology, ledger...). Copy what the image ships there into a writable volume first. Per pod and lost on
# restart: with more than one replica, keep state in Postgres (DATABASE_URL), not in these files.
- name: seed-state
image: tommiebot
command: ["sh", "-c", "if [ -d /app/.specify ]; then cp -R /app/.specify/. /state/; fi"]
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: [ALL] }
resources:
requests: { cpu: 10m, memory: 32Mi }
limits: { memory: 64Mi }
volumeMounts:
- { name: state, mountPath: /state }
containers:
- name: app
image: tommiebot
ports: [{ name: http, containerPort: 3000 }]
envFrom:
- configMapRef: { name: tommiebot-config }
# kubectl create secret generic tommiebot-secrets --from-env-file=.env (see docs/deploy/kubernetes.md)
- secretRef: { name: tommiebot-secrets, optional: true }
# First boot compiles nothing (standalone build) but cold-starts Node; give it a minute before liveness counts.
startupProbe:
httpGet: { path: /api/healthz, port: http }
periodSeconds: 2
failureThreshold: 30
readinessProbe:
httpGet: { path: /api/healthz, port: http }
periodSeconds: 10
failureThreshold: 3
livenessProbe:
httpGet: { path: /api/healthz, port: http }
periodSeconds: 20
failureThreshold: 3
# Let the Service and ingress stop sending traffic before Node gets SIGTERM.
lifecycle:
preStop:
exec: { command: ["sleep", "5"] }
resources:
requests: { cpu: 250m, memory: 384Mi }
limits: { memory: 1Gi }
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: [ALL] }
volumeMounts:
- { name: next-cache, mountPath: /app/.next/cache }
- { name: state, mountPath: /app/.specify }
- { name: tmp, mountPath: /tmp }
volumes:
- { name: next-cache, emptyDir: { sizeLimit: 512Mi } }
- { name: state, emptyDir: { sizeLimit: 256Mi } }
- { name: tmp, emptyDir: { sizeLimit: 256Mi } }
---
apiVersion: v1
kind: Service
metadata:
name: tommiebot
labels: { app: tommiebot, app.kubernetes.io/name: tommiebot }
spec:
selector: { app: tommiebot }
ports: [{ name: http, port: 80, targetPort: http }]
# CPU-based scaling (needs metrics-server) and a floor during voluntary disruptions (node drains, upgrades).
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: tommiebot
spec:
scaleTargetRef: { apiVersion: apps/v1, kind: Deployment, name: tommiebot }
minReplicas: 2
maxReplicas: 6
metrics:
- type: Resource
resource: { name: cpu, target: { type: Utilization, averageUtilization: 70 } }
behavior:
# Chat answers stream for up to a minute: scale down slowly so a pod is not cut mid-answer.
scaleDown:
stabilizationWindowSeconds: 300
policies: [{ type: Pods, value: 1, periodSeconds: 60 }]
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: tommiebot
spec:
minAvailable: 1
selector:
matchLabels: { app: tommiebot }
# Generated by `pnpm crons:sync` from config/cron-schedule.json. Do not edit by hand.
# Disabled jobs are suspended; run one by hand: kubectl create job --from=cronjob/<name> <name>-manual
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-cron-research-loops
labels:
app.kubernetes.io/component: cron
spec:
schedule: "*/30 * * * *"
suspend: true
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: tommiebot-cron
app.kubernetes.io/component: cron
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: call
image: tommiebot
command:
- node
- -e
- |-
const url = new URL(process.env.CRON_PATH, process.env.APP_URL)
fetch(url, { headers: { authorization: 'Bearer ' + (process.env.CRON_SECRET || '') }, signal: AbortSignal.timeout(280000) })
.then(async (r) => { console.log(r.status, url.pathname, (await r.text()).slice(0, 500)); process.exit(r.ok ? 0 : 1) })
.catch((e) => { console.error(url.pathname, e.message); process.exit(1) })
env:
- name: CRON_PATH
value: /api/cron/research-loops
- name: APP_URL
value: http://tommiebot
- name: CRON_SECRET
valueFrom:
secretKeyRef:
name: tommiebot-secrets
key: CRON_SECRET
optional: true
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-cron-agents
labels:
app.kubernetes.io/component: cron
spec:
schedule: "*/15 * * * *"
suspend: true
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: tommiebot-cron
app.kubernetes.io/component: cron
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: call
image: tommiebot
command:
- node
- -e
- |-
const url = new URL(process.env.CRON_PATH, process.env.APP_URL)
fetch(url, { headers: { authorization: 'Bearer ' + (process.env.CRON_SECRET || '') }, signal: AbortSignal.timeout(280000) })
.then(async (r) => { console.log(r.status, url.pathname, (await r.text()).slice(0, 500)); process.exit(r.ok ? 0 : 1) })
.catch((e) => { console.error(url.pathname, e.message); process.exit(1) })
env:
- name: CRON_PATH
value: /api/cron/agents
- name: APP_URL
value: http://tommiebot
- name: CRON_SECRET
valueFrom:
secretKeyRef:
name: tommiebot-secrets
key: CRON_SECRET
optional: true
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-cron-provenance
labels:
app.kubernetes.io/component: cron
spec:
schedule: 0 6 * * *
suspend: true
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: tommiebot-cron
app.kubernetes.io/component: cron
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: call
image: tommiebot
command:
- node
- -e
- |-
const url = new URL(process.env.CRON_PATH, process.env.APP_URL)
fetch(url, { headers: { authorization: 'Bearer ' + (process.env.CRON_SECRET || '') }, signal: AbortSignal.timeout(280000) })
.then(async (r) => { console.log(r.status, url.pathname, (await r.text()).slice(0, 500)); process.exit(r.ok ? 0 : 1) })
.catch((e) => { console.error(url.pathname, e.message); process.exit(1) })
env:
- name: CRON_PATH
value: /api/cron/provenance
- name: APP_URL
value: http://tommiebot
- name: CRON_SECRET
valueFrom:
secretKeyRef:
name: tommiebot-secrets
key: CRON_SECRET
optional: true
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-cron-paper-queue
labels:
app.kubernetes.io/component: cron
spec:
schedule: 0 5 * * *
suspend: true
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: tommiebot-cron
app.kubernetes.io/component: cron
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: call
image: tommiebot
command:
- node
- -e
- |-
const url = new URL(process.env.CRON_PATH, process.env.APP_URL)
fetch(url, { headers: { authorization: 'Bearer ' + (process.env.CRON_SECRET || '') }, signal: AbortSignal.timeout(280000) })
.then(async (r) => { console.log(r.status, url.pathname, (await r.text()).slice(0, 500)); process.exit(r.ok ? 0 : 1) })
.catch((e) => { console.error(url.pathname, e.message); process.exit(1) })
env:
- name: CRON_PATH
value: /api/cron/paper-queue
- name: APP_URL
value: http://tommiebot
- name: CRON_SECRET
valueFrom:
secretKeyRef:
name: tommiebot-secrets
key: CRON_SECRET
optional: true
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-cron-deployments
labels:
app.kubernetes.io/component: cron
spec:
schedule: "*/30 * * * *"
suspend: true
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: tommiebot-cron
app.kubernetes.io/component: cron
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: call
image: tommiebot
command:
- node
- -e
- |-
const url = new URL(process.env.CRON_PATH, process.env.APP_URL)
fetch(url, { headers: { authorization: 'Bearer ' + (process.env.CRON_SECRET || '') }, signal: AbortSignal.timeout(280000) })
.then(async (r) => { console.log(r.status, url.pathname, (await r.text()).slice(0, 500)); process.exit(r.ok ? 0 : 1) })
.catch((e) => { console.error(url.pathname, e.message); process.exit(1) })
env:
- name: CRON_PATH
value: /api/cron/deployments
- name: APP_URL
value: http://tommiebot
- name: CRON_SECRET
valueFrom:
secretKeyRef:
name: tommiebot-secrets
key: CRON_SECRET
optional: true
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-cron-perf
labels:
app.kubernetes.io/component: cron
spec:
schedule: 0 */6 * * *
suspend: true
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: tommiebot-cron
app.kubernetes.io/component: cron
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: call
image: tommiebot
command:
- node
- -e
- |-
const url = new URL(process.env.CRON_PATH, process.env.APP_URL)
fetch(url, { headers: { authorization: 'Bearer ' + (process.env.CRON_SECRET || '') }, signal: AbortSignal.timeout(280000) })
.then(async (r) => { console.log(r.status, url.pathname, (await r.text()).slice(0, 500)); process.exit(r.ok ? 0 : 1) })
.catch((e) => { console.error(url.pathname, e.message); process.exit(1) })
env:
- name: CRON_PATH
value: /api/cron/perf
- name: APP_URL
value: http://tommiebot
- name: CRON_SECRET
valueFrom:
secretKeyRef:
name: tommiebot-secrets
key: CRON_SECRET
optional: true
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-cron-portfolio-pull
labels:
app.kubernetes.io/component: cron
spec:
schedule: 0 * * * *
suspend: true
concurrencyPolicy: Forbid
startingDeadlineSeconds: 300
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 1
activeDeadlineSeconds: 300
ttlSecondsAfterFinished: 86400
template:
metadata:
labels:
app: tommiebot-cron
app.kubernetes.io/component: cron
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile:
type: RuntimeDefault
containers:
- name: call
image: tommiebot
command:
- node
- -e
- |-
const url = new URL(process.env.CRON_PATH, process.env.APP_URL)
fetch(url, { headers: { authorization: 'Bearer ' + (process.env.CRON_SECRET || '') }, signal: AbortSignal.timeout(280000) })
.then(async (r) => { console.log(r.status, url.pathname, (await r.text()).slice(0, 500)); process.exit(r.ok ? 0 : 1) })
.catch((e) => { console.error(url.pathname, e.message); process.exit(1) })
env:
- name: CRON_PATH
value: /api/cron/portfolio-pull
- name: APP_URL
value: http://tommiebot
- name: CRON_SECRET
valueFrom:
secretKeyRef:
name: tommiebot-secrets
key: CRON_SECRET
optional: true
resources:
requests:
cpu: 10m
memory: 64Mi
limits:
memory: 128Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
# The app on any Kubernetes: Deployment + Service + autoscaling + disruption budget + network policy, the scheduled
# jobs (crons.generated.yaml, from config/cron-schedule.json) and the migration template (migrate.yaml).
# Pick an overlay rather than applying this directly: deploy/k8s/overlays/{dev,production,hybrid,on-prem,llm-d}.
# Guide: docs/deploy/kubernetes.md
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
labels:
- pairs:
app.kubernetes.io/part-of: tommiebot
includeSelectors: false
includeTemplates: true
resources:
- serviceaccount.yaml
- app.yaml
- autoscaling.yaml
- networkpolicy.yaml
- migrate.yaml
- crons.generated.yaml
# Every manifest names its images `tommiebot` and `tommiebot-sql-proxy`; each overlay maps them to a registry and
# tag in its own `images:` list (a rename here would hide the name from the overlays), so the app, the migration and
# the cron Jobs always run the same build.
# Migrations, as a template that never fires on its own (suspended). Run it before each rollout; every migration is
# idempotent, so running it twice changes nothing:
# kubectl create job --from=cronjob/tommiebot-migrate tommiebot-migrate-$(date +%s)
# scripts/k8s/deploy.sh does this for you and waits for it before rolling the Deployment.
apiVersion: batch/v1
kind: CronJob
metadata:
name: tommiebot-migrate
labels: { app.kubernetes.io/component: migrate }
spec:
schedule: "0 0 1 1 *"
suspend: true
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 2
activeDeadlineSeconds: 600
ttlSecondsAfterFinished: 86400
template:
metadata:
labels: { app: tommiebot-migrate, app.kubernetes.io/component: migrate, tommiebot/db-client: "true" }
spec:
restartPolicy: Never
serviceAccountName: tommiebot
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1001
runAsGroup: 1001
seccompProfile: { type: RuntimeDefault }
containers:
- name: migrate
image: tommiebot
command: ["node", "--experimental-strip-types", "--no-warnings", "scripts/db-migrate.ts"]
envFrom:
- configMapRef: { name: tommiebot-config }
- secretRef: { name: tommiebot-secrets, optional: true }
resources:
requests: { cpu: 50m, memory: 128Mi }
limits: { memory: 256Mi }
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: [ALL] }
# Default for the app's pods (web, migration, crons): anyone may reach the web port (the ingress controller lives in
# another namespace); out, only DNS, anything in this namespace, and HTTP(S) to the outside (AI Gateway, Neon,
# GitHub, model providers). The data tier (in-cluster Postgres and its /sql proxy) is excluded here and gets a
# stricter policy of its own from its component; llm-d adds an egress rule to its namespace.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: tommiebot
spec:
podSelector:
matchLabels: { app.kubernetes.io/part-of: tommiebot }
matchExpressions:
- { key: app.kubernetes.io/component, operator: NotIn, values: [database, sql-proxy] }
policyTypes: [Ingress, Egress]
ingress:
- ports: [{ port: 3000, protocol: TCP }]
- from: [{ podSelector: {} }]
egress:
- ports: [{ port: 53, protocol: UDP }, { port: 53, protocol: TCP }]
- to: [{ podSelector: {} }]
- ports: [{ port: 443, protocol: TCP }, { port: 80, protocol: TCP }]
# The app never talks to the Kubernetes API: no token is mounted into any of its pods.
apiVersion: v1
kind: ServiceAccount
metadata:
name: tommiebot
automountServiceAccountToken: false
# Postgres in the cluster instead of Neon: a single-instance StatefulSet and the /sql proxy (deploy/sql-proxy) that
# lets the app's Neon driver talk to it unchanged. The app keeps a DATABASE_URL only because the driver needs one;
# the proxy connects with its own credentials from the `tommiebot-postgres` Secret:
# kubectl create secret generic tommiebot-postgres \
# --from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 24)"
# For production data use a managed Postgres or an operator (CloudNativePG) and point the proxy's DATABASE_URL at it.
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- postgres.yaml
- sql-proxy.yaml
- networkpolicy.yaml
patches:
- target: { kind: ConfigMap, name: tommiebot-config }
patch: |-
- op: replace
path: /data/DATABASE_HTTP_ENDPOINT
value: http://tommiebot-sql-proxy:4444/sql
- op: add
path: /data/DATABASE_URL
value: postgresql://tommiebot@tommiebot-postgres:5432/tommiebot
# Only the app's database clients (web, migration) reach the proxy, and only the proxy reaches Postgres.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: tommiebot-sql-proxy
spec:
podSelector:
matchLabels: { app: tommiebot-sql-proxy }
policyTypes: [Ingress, Egress]
ingress:
- from: [{ podSelector: { matchLabels: { tommiebot/db-client: "true" } } }]
ports: [{ port: 4444, protocol: TCP }]
egress:
- ports: [{ port: 53, protocol: UDP }, { port: 53, protocol: TCP }]
- to: [{ podSelector: { matchLabels: { app: tommiebot-postgres } } }]
ports: [{ port: 5432, protocol: TCP }]
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: tommiebot-postgres
spec:
podSelector:
matchLabels: { app: tommiebot-postgres }
policyTypes: [Ingress, Egress]
ingress:
- from: [{ podSelector: { matchLabels: { app: tommiebot-sql-proxy } } }]
ports: [{ port: 5432, protocol: TCP }]
egress: []
apiVersion: v1
kind: Service
metadata:
name: tommiebot-postgres
labels: { app: tommiebot-postgres, app.kubernetes.io/component: database }
spec:
selector: { app: tommiebot-postgres }
ports: [{ name: postgres, port: 5432, targetPort: postgres }]
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: tommiebot-postgres
labels: { app: tommiebot-postgres, app.kubernetes.io/component: database }
spec:
serviceName: tommiebot-postgres
replicas: 1
selector:
matchLabels: { app: tommiebot-postgres }
template:
metadata:
labels: { app: tommiebot-postgres, app.kubernetes.io/component: database }
spec:
automountServiceAccountToken: false
terminationGracePeriodSeconds: 60
securityContext:
runAsNonRoot: true
runAsUser: 70
runAsGroup: 70
fsGroup: 70
seccompProfile: { type: RuntimeDefault }
containers:
- name: postgres
image: postgres:17-alpine
ports: [{ name: postgres, containerPort: 5432 }]
env:
- { name: POSTGRES_DB, value: tommiebot }
- { name: POSTGRES_USER, value: tommiebot }
- name: POSTGRES_PASSWORD
valueFrom: { secretKeyRef: { name: tommiebot-postgres, key: POSTGRES_PASSWORD } }
- { name: PGDATA, value: /var/lib/postgresql/data/pgdata }
readinessProbe:
exec: { command: ["pg_isready", "-U", "tommiebot", "-d", "tommiebot"] }
periodSeconds: 5
livenessProbe:
exec: { command: ["pg_isready", "-U", "tommiebot", "-d", "tommiebot"] }
initialDelaySeconds: 30
periodSeconds: 20
resources:
requests: { cpu: 100m, memory: 256Mi }
limits: { memory: 1Gi }
securityContext:
allowPrivilegeEscalation: false
capabilities: { drop: [ALL] }
volumeMounts:
- { name: data, mountPath: /var/lib/postgresql/data }
- { name: run, mountPath: /var/run/postgresql }
volumes:
- { name: run, emptyDir: {} }
volumeClaimTemplates:
- metadata: { name: data }
spec:
accessModes: [ReadWriteOnce]
resources: { requests: { storage: 5Gi } }
# deploy/sql-proxy: the Neon driver's /sql protocol in front of tommiebot-postgres.
apiVersion: v1
kind: Service
metadata:
name: tommiebot-sql-proxy
labels: { app: tommiebot-sql-proxy, app.kubernetes.io/component: sql-proxy }
spec:
selector: { app: tommiebot-sql-proxy }
ports: [{ name: http, port: 4444, targetPort: http }]
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: tommiebot-sql-proxy
labels: { app: tommiebot-sql-proxy, app.kubernetes.io/component: sql-proxy }
spec:
replicas: 2
selector:
matchLabels: { app: tommiebot-sql-proxy }
template:
metadata:
labels: { app: tommiebot-sql-proxy, app.kubernetes.io/component: sql-proxy }
spec:
automountServiceAccountToken: false
securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
seccompProfile: { type: RuntimeDefault }
containers:
- name: proxy
image: tommiebot-sql-proxy
ports: [{ name: http, containerPort: 4444 }]
env:
- name: POSTGRES_PASSWORD
valueFrom: { secretKeyRef: { name: tommiebot-postgres, key: POSTGRES_PASSWORD } }
- { name: DATABASE_URL, value: "postgresql://tommiebot:$(POSTGRES_PASSWORD)@tommiebot-postgres:5432/tommiebot" }
- { name: PG_POOL_MAX, value: "10" }
# Optional shared secret; set the same value as DATABASE_HTTP_TOKEN in tommiebot-secrets.
- name: PROXY_TOKEN
valueFrom: { secretKeyRef: { name: tommiebot-postgres, key: PROXY_TOKEN, optional: true } }
readinessProbe:
httpGet: { path: /healthz, port: http }
periodSeconds: 5
livenessProbe:
httpGet: { path: /livez, port: http }
periodSeconds: 20
resources:
requests: { cpu: 50m, memory: 64Mi }
limits: { memory: 256Mi }
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities: { drop: [ALL] }
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: tommiebot
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/proxy-buffering: "off"
nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
nginx.ingress.kubernetes.io/proxy-send-timeout: "300"
nginx.ingress.kubernetes.io/proxy-body-size: 25m
spec:
ingressClassName: nginx
tls:
- hosts: [tommiebot.example.edu]
secretName: tommiebot-tls
rules:
- host: tommiebot.example.edu
http:
paths:
- path: /
pathType: Prefix
backend:
service: { name: tommiebot, port: { name: http } }
# A public HTTPS entry through ingress-nginx and cert-manager. Overlays replace the host (and the issuer if yours
# is not letsencrypt-prod). Streaming chat answers need buffering off and a long read timeout.
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- ingress.yaml
# Route "local/<model>" requests to an llm-d stack in the same cluster (vLLM behind its OpenAI-compatible inference
# gateway). Install llm-d first with its own guides, then check the Service name below:
# kubectl get svc -n llm-d
# Models from the AI Gateway keep working: pick "local/<model>" in the model menu to use the cluster's GPUs.
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
resources:
- networkpolicy.yaml
patches:
- target: { kind: ConfigMap, name: tommiebot-config }
patch: |-
- op: replace
path: /data/LOCAL_LLM_BASE_URL
value: http://llm-d-inference-gateway.llm-d.svc.cluster.local/v1
- op: replace
path: /data/LOCAL_LLM_ALLOW_REMOTE
value: "true"
# The app may call the inference gateway in the llm-d namespace (plain HTTP inside the cluster).
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: tommiebot-to-llm-d
spec:
podSelector:
matchLabels: { app: tommiebot }
policyTypes: [Egress]
egress:
- to: [{ namespaceSelector: { matchLabels: { kubernetes.io/metadata.name: llm-d } } }]
ports: [{ port: 80, protocol: TCP }, { port: 8000, protocol: TCP }, { port: 8080, protocol: TCP }]
# Local cluster (kind, k3d, minikube, Docker Desktop): everything in-cluster, images built on this machine.
# scripts/k8s/e2e.sh builds both images, loads them into kind, applies this, migrates and checks health
# Demo access codes and a throwaway Postgres password: never use this overlay for real users.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: tommiebot-dev
resources:
- namespace.yaml
- ../../base
components:
- ../../components/in-cluster-postgres
images:
- name: tommiebot
newName: tommiebot
newTag: dev
- name: tommiebot-sql-proxy
newName: tommiebot-sql-proxy
newTag: dev
secretGenerator:
- name: tommiebot-postgres
literals:
- POSTGRES_PASSWORD=dev-only-postgres-password
- name: tommiebot-secrets
literals:
- STUDENT_ACCESS_CODE=demo-student
- PROFESSOR_ACCESS_CODE=demo-professor
- ADMIN_ACCESS_CODE=demo-admin-local
- AGENT_ACCESS_CODE=demo-agent
- ACCESS_SESSION_SECRET=dev-only-session-secret-change-me
- CRON_SECRET=dev-only-cron-secret
- ADMIN_GATE=off
- STACK_SECRET_SERVER_KEY=ssk_demo_placeholder
generatorOptions:
disableNameSuffixHash: true
patches:
# One replica, scaled 1..2: a laptop cluster has one node and no metrics-server by default.
- target: { kind: Deployment, name: tommiebot }
patch: |-
- op: replace
path: /spec/replicas
value: 1
- target: { kind: HorizontalPodAutoscaler, name: tommiebot }
patch: |-
- op: replace
path: /spec/minReplicas
value: 1
- op: replace
path: /spec/maxReplicas
value: 2
- target: { kind: Deployment, name: tommiebot-sql-proxy }
patch: |-
- op: replace
path: /spec/replicas
value: 1
- target: { kind: StatefulSet, name: tommiebot-postgres }
patch: |-
- op: replace
path: /spec/volumeClaimTemplates/0/spec/resources/requests/storage
value: 1Gi
apiVersion: v1
kind: Namespace
metadata:
name: tommiebot-dev
# Hybrid: the production setup (Neon, AI Gateway, public HTTPS) plus open models on the cluster's own GPUs through
# llm-d. Hosted models and local models sit side by side in the model menu; "local/<model>" stays in the cluster.
# Install llm-d first (its own guides), then: scripts/k8s/deploy.sh hybrid <image-tag>
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../production
components:
- ../../components/llm-d
# Kept for existing users of `kubectl apply -k deploy/k8s/overlays/llm-d`: the base plus the llm-d component.
# New setups: use overlays/hybrid (with ingress and Neon) or overlays/on-prem (everything in the cluster).
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../../base
components:
- ../../components/llm-d
images:
- name: tommiebot
newName: ghcr.io/johnaffolter/ust-tommiebot-platform
newTag: latest
# On-premises: no managed cloud database. Postgres runs in the cluster (through the /sql proxy), open models run on
# llm-d, and HTTPS comes in through the ingress. Hosted models still work when AI_GATEWAY_API_KEY is set; leave it
# unset and set AI_OFFLINE_FALLBACK as you need for a cluster with no outside access.
# Before the first apply:
# kubectl create namespace tommiebot
# kubectl -n tommiebot create secret generic tommiebot-secrets --from-env-file=.env.production
# kubectl -n tommiebot create secret generic tommiebot-postgres --from-literal=POSTGRES_PASSWORD="$(openssl rand -hex 24)"
# Build and push deploy/sql-proxy as well as the app (scripts/k8s/deploy.sh on-prem <image-tag> sets both tags).
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../production
components:
- ../../components/in-cluster-postgres
- ../../components/llm-d
images:
- name: tommiebot-sql-proxy
newName: ghcr.io/johnaffolter/tommiebot-sql-proxy
newTag: CHANGE-ME
# Cloud services, cluster compute: the app runs here, the database is Neon (DATABASE_URL in tommiebot-secrets),
# models come from the AI Gateway (AI_GATEWAY_API_KEY), and HTTPS comes in through ingress-nginx + cert-manager.
# Before the first apply:
# kubectl create namespace tommiebot
# kubectl -n tommiebot create secret generic tommiebot-secrets --from-env-file=.env.production
# Then: scripts/k8s/deploy.sh production <image-tag>
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: tommiebot
resources:
- ../../base
components:
- ../../components/ingress
images:
# Pin a tag you built and pushed (scripts/k8s/deploy.sh sets it); never run production from :latest.
- name: tommiebot
newName: ghcr.io/johnaffolter/ust-tommiebot-platform
newTag: CHANGE-ME
patches:
- target: { kind: Deployment, name: tommiebot }
patch: |-
- op: replace
path: /spec/replicas
value: 3
- target: { kind: HorizontalPodAutoscaler, name: tommiebot }
patch: |-
- op: replace
path: /spec/minReplicas
value: 3
- op: replace
path: /spec/maxReplicas
value: 10
- target: { kind: PodDisruptionBudget, name: tommiebot }
patch: |-
- op: replace
path: /spec/minAvailable
value: 2
# The public origin: links in responses and emails. Build the image with the same value
# (--build-arg NEXT_PUBLIC_APP_URL=...), which sign-in emails compile in.
- target: { kind: ConfigMap, name: tommiebot-config }
patch: |-
- op: add
path: /data/NEXT_PUBLIC_APP_URL
value: https://tommiebot.example.edu
# Your public host name (and the TLS certificate cert-manager issues for it).
- target: { kind: Ingress, name: tommiebot }
patch: |-
- op: replace
path: /spec/tls/0/hosts/0
value: tommiebot.example.edu
- op: replace
path: /spec/rules/0/host
value: tommiebot.example.edu
Production Kubernetes Deployment Guide: Complete K8s configuration for Neo4j/Snowflake data pipeline services. An example for a different system (a Neo4j and Snowflake data pipeline), kept for teaching. It is not what this repository runs.
┌─────────────────────────────────────────────────────────────┐ │ Kubernetes Cluster │ │ │ │ ┌────────────────────────────────────────────────────────┐ │ │ │ Namespace: neo4j-pipeline │ │ │ │ │ │ │ │ ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ │ CronJob │ │ CronJob │ │ │ │ │ │ aura-import │ │ gepa-alert │ │ │ │ │ │ (hourly @ :05) │ │ (every 6h) │ │ │ │ │ └──────────────────┘ └──────────────────┘ │ │ │ │ │ │ │ │ ┌──────────────────────────────────────────────────┐ │ │ │ │ │ Deployment: text2sql-api (3-10 replicas) │ │ │ │ │ │ + HPA (CPU 70%, Memory 80%) │ │ │ │ │ │ + PDB (minAvailable: 2) │ │ │ │ │ └──────────────────────────────────────────────────┘ │ │ │ │ ▲ │ │ │ │ │ │ │ │ │ ┌─────────────────────┴────────────────────────────┐ │ │ │ │ │ Service (ClusterIP) → Ingress (NGINX + TLS) │ │ │ │ │ └──────────────────────────────────────────────────┘ │ │ │ │ │ │ │ │ ConfigMaps: aura-config, snowflake-config │ │ │ │ Secrets: neo4j-credentials, snowflake-credentials │ │ │ └────────────────────────────────────────────────────────┘ │ │ │ │ External: Neo4j Aura, Snowflake, OpenAI/Anthropic │ └─────────────────────────────────────────────────────────────┘