apiVersion: apps/v1
kind: Deployment
metadata:
  name: n8n
  namespace: ai
spec:
  replicas: 1
  selector:
    matchLabels:
      app: n8n
  template:
    metadata:
      labels:
        app: n8n
    spec:
      containers:
        - name: n8n
          image: n8nio/n8n:latest
          ports:
            - containerPort: 5678
          env:
            # PostgreSQL
            - name: DB_TYPE
              value: "postgresdb"
            - name: DB_POSTGRESDB_HOST
              value: "192.168.10.1"
            - name: DB_POSTGRESDB_PORT
              value: "5432"
            - name: DB_POSTGRESDB_DATABASE
              value: "n8n"
            - name: DB_POSTGRESDB_USER
              value: "n8n"
            - name: DB_POSTGRESDB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: n8n-secret
                  key: db-password
            # Clé de chiffrement des credentials
            - name: N8N_ENCRYPTION_KEY
              valueFrom:
                secretKeyRef:
                  name: n8n-secret
                  key: encryption-key
            # URLs
            - name: N8N_HOST
              value: "0.0.0.0"
            - name: N8N_PORT
              value: "5678"
            - name: N8N_PROTOCOL
              value: "http"
            - name: WEBHOOK_URL
              value: "http://n8n.lab.local"
            - name: N8N_EDITOR_BASE_URL
              value: "http://n8n.lab.local"
            # Timezone
            - name: GENERIC_TIMEZONE
              value: "Europe/Paris"
            - name: TZ
              value: "Europe/Paris"
            # Désactiver la télémétrie
            - name: N8N_DIAGNOSTICS_ENABLED
              value: "false"
            - name: N8N_SECURE_COOKIE
              value: "false"
          volumeMounts:
            - name: data
              mountPath: /home/node/.n8n
          resources:
            requests:
              cpu: 200m
              memory: 256Mi
            limits:
              cpu: 1000m
              memory: 1Gi
          readinessProbe:
            httpGet:
              path: /healthz
              port: 5678
            initialDelaySeconds: 20
            periodSeconds: 10
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: n8n-data
