# vexplor Backend Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vexplor-backend
  namespace: vexplor
  labels:
    app: vexplor-backend
    component: backend
spec:
  replicas: 2
  selector:
    matchLabels:
      app: vexplor-backend
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: vexplor-backend
        component: backend
    spec:
      imagePullSecrets:
        - name: harbor-registry
      containers:
        - name: vexplor-backend
          image: harbor.wace.me/vexplor/vexplor-backend:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 3001
              protocol: TCP
          envFrom:
            - configMapRef:
                name: vexplor-config
            - secretRef:
                name: vexplor-secret
          env:
            - name: PORT
              value: "3001"
            - name: HOST
              value: "0.0.0.0"
          resources:
            requests:
              memory: "256Mi"
              cpu: "100m"
            limits:
              memory: "1Gi"
              cpu: "500m"
          livenessProbe:
            httpGet:
              path: /health
              port: 3001
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health
              port: 3001
            initialDelaySeconds: 10
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 3
          volumeMounts:
            - name: uploads
              mountPath: /app/uploads
            - name: data
              mountPath: /app/data
            - name: logs
              mountPath: /app/logs
      volumes:
        - name: uploads
          persistentVolumeClaim:
            claimName: vexplor-backend-uploads-pvc
        - name: data
          persistentVolumeClaim:
            claimName: vexplor-backend-data-pvc
        - name: logs
          emptyDir: {}

---
# Backend Service
apiVersion: v1
kind: Service
metadata:
  name: vexplor-backend-service
  namespace: vexplor
  labels:
    app: vexplor-backend
spec:
  type: ClusterIP
  selector:
    app: vexplor-backend
  ports:
    - name: http
      port: 3001
      targetPort: 3001
      protocol: TCP

---
# Backend PVC - Uploads
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: vexplor-backend-uploads-pvc
  namespace: vexplor
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: local-path

---
# Backend PVC - Data
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: vexplor-backend-data-pvc
  namespace: vexplor
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: local-path

