apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend-spring
  namespace: invyone
  labels:
    app: backend-spring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: backend-spring
  template:
    metadata:
      labels:
        app: backend-spring
    spec:
      containers:
        - name: backend-spring
          image: localhost:5000/invyone/backend-spring:latest
          ports:
            - containerPort: 8081
          env:
            - name: SPRING_PROFILES_ACTIVE
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: SPRING_PROFILES_ACTIVE
            - name: SERVER_PORT
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: SERVER_PORT
            - name: SPRING_DATASOURCE_URL
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: SPRING_DATASOURCE_URL
            - name: SPRING_DATASOURCE_USERNAME
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: SPRING_DATASOURCE_USERNAME
            - name: SPRING_DATASOURCE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: invyone-secrets
                  key: SPRING_DATASOURCE_PASSWORD
            - name: JWT_SECRET
              valueFrom:
                secretKeyRef:
                  name: invyone-secrets
                  key: JWT_SECRET
            - name: JWT_EXPIRATION
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: JWT_EXPIRATION
            - name: FILE_UPLOAD_DIR
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: FILE_UPLOAD_DIR
            - name: CORS_ALLOWED_ORIGINS
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: CORS_ALLOWED_ORIGINS
            - name: TENANT_PROVISIONING_REQUIRE_SUPER_ADMIN
              valueFrom:
                configMapKeyRef:
                  name: invyone-config
                  key: TENANT_PROVISIONING_REQUIRE_SUPER_ADMIN
          resources:
            requests:
              cpu: 250m
              memory: 512Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
          livenessProbe:
            tcpSocket:
              port: 8081
            initialDelaySeconds: 60
            periodSeconds: 30
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            tcpSocket:
              port: 8081
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          volumeMounts:
            - name: uploads
              mountPath: /app/uploads
      volumes:
        - name: uploads
          persistentVolumeClaim:
            claimName: invyone-uploads-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: backend-spring
  namespace: invyone
spec:
  type: NodePort
  selector:
    app: backend-spring
  ports:
    - port: 8081
      targetPort: 8081
      nodePort: 30081
