# NATS JetStream StatefulSet — durable messaging for multi-replica EDDI
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nats
  labels:
    app.kubernetes.io/name: nats
    app.kubernetes.io/component: messaging
    app.kubernetes.io/part-of: eddi
spec:
  serviceName: nats
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: nats
      app.kubernetes.io/component: messaging
  template:
    metadata:
      labels:
        app.kubernetes.io/name: nats
        app.kubernetes.io/component: messaging
        app.kubernetes.io/part-of: eddi
    spec:
      containers:
        - name: nats
          image: nats:2.10-alpine
          command: ["nats-server", "--jetstream", "--store_dir=/data", "-m", "8222"]
          ports:
            - containerPort: 4222
              name: client
            - containerPort: 8222
              name: monitoring
          volumeMounts:
            - name: nats-data
              mountPath: /data
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 500m
              memory: 256Mi
          livenessProbe:
            httpGet:
              path: /healthz
              port: monitoring
            initialDelaySeconds: 5
            periodSeconds: 15
          readinessProbe:
            httpGet:
              path: /healthz
              port: monitoring
            initialDelaySeconds: 3
            periodSeconds: 10
  volumeClaimTemplates:
    - metadata:
        name: nats-data
        labels:
          app.kubernetes.io/name: nats
          app.kubernetes.io/component: messaging
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 5Gi
