apiVersion: apps/v1
kind: Deployment
metadata:
  name: n8n
  namespace: n8n
  labels:
    app: n8n
spec:
  replicas: 1
  selector:
    matchLabels:
      app: n8n
  template:
    metadata:
      labels:
        app: n8n
    spec:
      securityContext:
        runAsUser: 1000
        runAsGroup: 1000
        fsGroup: 1000
      containers:
        - name: n8n
          image: n8nio/n8n:latest
          ports:
            - containerPort: 5678
          env:
            - name: N8N_HOST
              value: "n8n.cloud.mielito.com"
            - name: N8N_PORT
              value: "5678"
            - name: N8N_PROTOCOL
              value: "https"
            - name: WEBHOOK_URL
              value: "https://n8n.cloud.mielito.com/"
            - name: N8N_EDITOR_BASE_URL
              value: "https://n8n.cloud.mielito.com/"
            - name: GENERIC_TIMEZONE
              value: "Europe/Madrid"
            - name: TZ
              value: "Europe/Madrid"
            - name: N8N_ENCRYPTION_KEY
              value: "e8e6ba5387ee85a256dcf51dc9898bb2d72e2433110273d5831c38d6a9220398"
            - name: N8N_USER_MANAGEMENT_DISABLED
              value: "false"
            - name: N8N_BASIC_AUTH_ACTIVE
              value: "false"
          volumeMounts:
            - name: n8n-data
              mountPath: /home/node/.n8n
          resources:
            requests:
              memory: "256Mi"
              cpu: "100m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          livenessProbe:
            httpGet:
              path: /healthz
              port: 5678
            initialDelaySeconds: 30
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /healthz
              port: 5678
            initialDelaySeconds: 10
            periodSeconds: 5
      volumes:
        - name: n8n-data
          persistentVolumeClaim:
            claimName: n8n-data
