Files
infra-n8n/k8s/postgres/statefulset.yaml
T
Stéphane Tailland dc13738e86 feat: deploy n8n on the cluster
The runtime for the estate's autonomous agents. Postgres as a StatefulSet with
its own claim, n8n behind a cert-manager certificate and the nginx ingress, and
both secrets in Vault behind an AppRole scoped to n8n/* alone.

The certificate is issued into the cluster rather than copied into the repo, so
the private key never reaches git. The CA certificate is committed and mounted
as NODE_EXTRA_CA_CERTS, so a workflow can reach keycloak and the domain
gateways without anyone disabling verification to make it work.

One replica and strategy: Recreate, both deliberate — n8n needs Redis and queue
mode before a second scheduler is safe, and a ReadWriteOnce volume deadlocks a
rolling update.

N8N_ENCRYPTION_KEY is generated once and kept in Vault. Regenerating it does not
re-encrypt the stored credentials, it orphans them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 12:34:40 +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: n8n
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:16.10-alpine
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: 5Gi