apiVersion: apps/v1
kind: Deployment
metadata:
  name: vapora-backend
  namespace: vapora
  labels:
    app: vapora-backend
    component: api
spec:
  replicas: 2
  selector:
    matchLabels:
      app: vapora-backend
  template:
    metadata:
      labels:
        app: vapora-backend
        component: api
    spec:
      containers:
      - name: backend
        image: vapora/backend:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        env:
        - name: RUST_LOG
          value: "info,vapora=debug"
        - name: SURREALDB_URL
          value: "http://surrealdb:8000"
        - name: SURREALDB_USER
          valueFrom:
            secretKeyRef:
              name: vapora-secrets
              key: surrealdb-user
        - name: SURREALDB_PASS
          valueFrom:
            secretKeyRef:
              name: vapora-secrets
              key: surrealdb-pass
        - name: NATS_URL
          value: "nats://nats:4222"
        - name: JWT_SECRET
          valueFrom:
            secretKeyRef:
              name: vapora-secrets
              key: jwt-secret
        - name: BIND_ADDR
          value: "0.0.0.0:8080"
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
          timeoutSeconds: 3
          failureThreshold: 3
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 500m
            memory: 512Mi

---
apiVersion: v1
kind: Service
metadata:
  name: vapora-backend
  namespace: vapora
  labels:
    app: vapora-backend
    component: api
spec:
  selector:
    app: vapora-backend
  ports:
  - port: 8080
    targetPort: 8080
    name: http
    protocol: TCP
  type: ClusterIP
