apiVersion: apps/v1
kind: Deployment
metadata:
  name: dashboard-service
  namespace: erp
  labels:
    app: dashboard-service
    version: v1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: dashboard-service
  template:
    metadata:
      labels:
        app: dashboard-service
        version: v1
    spec:
      containers:
        - name: dashboard-service
          image: erp-dashboard-service:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8086
              name: http
              protocol: TCP
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: "prod"
            - name: DB_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: DB_HOST
            - name: DB_PORT
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: DB_PORT
            - name: DB_NAME
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: DB_NAME
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: erp-secrets
                  key: DB_USER
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: erp-secrets
                  key: DB_PASSWORD
            - name: REDIS_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: REDIS_HOST
            - name: REDIS_PORT
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: REDIS_PORT
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: erp-secrets
                  key: REDIS_PASSWORD
            - name: NACOS_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: NACOS_HOST
            - name: NACOS_PORT
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: NACOS_PORT
          resources:
            requests:
              memory: "512Mi"
              cpu: "250m"
            limits:
              memory: "1Gi"
              cpu: "500m"
          livenessProbe:
            httpGet:
              path: /actuator/health/liveness
              port: 8086
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /actuator/health/readiness
              port: 8086
            initialDelaySeconds: 30
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 3
          lifecycle:
            preStop:
              exec:
                command:
                  - /bin/sh
                  - -c
                  - sleep 10
---
apiVersion: v1
kind: Service
metadata:
  name: dashboard-service
  namespace: erp
  labels:
    app: dashboard-service
spec:
  type: ClusterIP
  ports:
    - port: 8086
      targetPort: 8086
      protocol: TCP
      name: http
  selector:
    app: dashboard-service
---
apiVersion: v1
kind: Service
metadata:
  name: dashboard-service-external
  namespace: erp
  labels:
    app: dashboard-service
spec:
  type: NodePort
  ports:
    - port: 8086
      targetPort: 8086
      nodePort: 30086
      protocol: TCP
      name: http
  selector:
    app: dashboard-service
