# Inventory Service Deployment Configuration
# 库存盘点服务部署配置

apiVersion: apps/v1
kind: Deployment
metadata:
  name: inventory-service
  namespace: erp
  labels:
    app: inventory-service
    version: v1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: inventory-service
      version: v1
  template:
    metadata:
      labels:
        app: inventory-service
        version: v1
    spec:
      containers:
        - name: inventory-service
          image: erp/inventory-service:1.0.0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8084
              name: http
          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_USERNAME
              valueFrom:
                secretKeyRef:
                  name: erp-secrets
                  key: DB_USERNAME
            - 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_SERVER
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: NACOS_SERVER
          resources:
            requests:
              memory: "512Mi"
              cpu: "250m"
            limits:
              memory: "1Gi"
              cpu: "500m"
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: 8084
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: 8084
            initialDelaySeconds: 30
            periodSeconds: 5
            timeoutSeconds: 3
            failureThreshold: 3
---
apiVersion: v1
kind: Service
metadata:
  name: inventory-service
  namespace: erp
spec:
  type: ClusterIP
  ports:
    - port: 8084
      targetPort: 8084
      protocol: TCP
      name: http
  selector:
    app: inventory-service
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: inventory-service
  namespace: erp
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /api/stocks/$2
spec:
  rules:
    - host: erp.erpzbbh.cn
      http:
        paths:
          - path: /stocks-api(/|$)(.*)
            pathType: Prefix
            backend:
              service:
                name: inventory-service
                port:
                  number: 8084
