apiVersion: v1
kind: ConfigMap
metadata:
  name: nats-config
  namespace: vapora
data:
  nats.conf: |
    port: 4222
    http_port: 8222

    jetstream {
      store_dir: /data
      max_memory_store: 256MB
      max_file_store: 1GB
    }

    # Logging
    debug: false
    trace: false
    logtime: true

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nats
  namespace: vapora
  labels:
    app: nats
    component: messaging
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nats
  template:
    metadata:
      labels:
        app: nats
        component: messaging
    spec:
      containers:
      - name: nats
        image: nats:latest
        ports:
        - containerPort: 4222
          name: client
          protocol: TCP
        - containerPort: 8222
          name: monitor
          protocol: TCP
        args:
        - "-c"
        - "/etc/nats/nats.conf"
        volumeMounts:
        - name: config
          mountPath: /etc/nats
        - name: data
          mountPath: /data
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8222
          initialDelaySeconds: 5
          periodSeconds: 5
          timeoutSeconds: 3
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8222
          initialDelaySeconds: 2
          periodSeconds: 3
          timeoutSeconds: 2
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 300m
            memory: 512Mi
      volumes:
      - name: config
        configMap:
          name: nats-config
      - name: data
        emptyDir: {}

---
apiVersion: v1
kind: Service
metadata:
  name: nats
  namespace: vapora
  labels:
    app: nats
    component: messaging
spec:
  selector:
    app: nats
  ports:
  - port: 4222
    targetPort: 4222
    name: client
    protocol: TCP
  - port: 8222
    targetPort: 8222
    name: monitor
    protocol: TCP
  type: ClusterIP
