Files
infra-n8n/k8s/postgres/statefulset.yaml
T
Stéphane Tailland d68d20c6f4 refactor: make this a reusable deployment, not ours
Every environment value is a ${VAR} for the caller to substitute: hostname,
images, storage, ingress class, TLS issuer, Vault server and path, timezone,
retention. Nothing in k8s/ names a host, a realm, an agent or an estate.

Removed: the Flux plumbing under dev/, which described one deployment, and the
ExternalSecret pulling a specific agent's Keycloak client secret. Both belong to
whoever deploys this. The lab CA ConfigMap goes with them — the mount stays,
parameterised and marked optional, because 'trust a private CA' is a property of
an environment and not of n8n.

The README is now the template's: how to consume it, what every variable means,
and the three things it deliberately does not do.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 13:10:05 +02:00

72 lines
2.1 KiB
YAML

# A StatefulSet rather than a Deployment: one identity, one volume, and no
# window where two pods hold the same data directory. The volumeClaimTemplate
# also means the claim is not deleted with the workload — losing the workflows
# to a `kubectl delete deploy` would be an avoidable way to lose them.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: n8n-postgres
namespace: ${NAMESPACE}
spec:
serviceName: n8n-postgres
replicas: 1
selector:
matchLabels:
app: n8n-postgres
template:
metadata:
labels:
app: n8n-postgres
spec:
securityContext:
fsGroup: 999
containers:
- name: postgres
image: ${POSTGRES_IMAGE}
ports:
- name: postgres
containerPort: 5432
env:
- name: POSTGRES_USER
value: n8n
- name: POSTGRES_DB
value: n8n
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: n8n-secrets
key: DB_PASSWORD
# The image initialises into this directory. Naming a subdirectory
# of the mount rather than the mount itself keeps initdb away from
# the lost+found some volume types leave at the root.
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
readinessProbe:
exec:
command: ["pg_isready", "-U", "n8n", "-d", "n8n"]
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
exec:
command: ["pg_isready", "-U", "n8n", "-d", "n8n"]
initialDelaySeconds: 30
periodSeconds: 20
resources:
requests:
cpu: 50m
memory: 256Mi
limits:
cpu: "1"
memory: 1Gi
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: ${POSTGRES_STORAGE}