# Kubernetes Deployment Configuration for Warehouse Service
apiVersion: apps/v1
kind: Deployment
metadata:
  name: warehouse-service
  namespace: erp
  labels:
    app: warehouse-service
    version: v1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: warehouse-service
  template:
    metadata:
      labels:
        app: warehouse-service
        version: v1
    spec:
      containers:
        - name: warehouse-service
          image: registry.erpzbbh.cn/warehouse-service:1.0.0
          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_PASS
              valueFrom:
                secretKeyRef:
                  name: erp-secrets
                  key: DB_PASS
            - name: REDIS_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: REDIS_HOST
            - name: NACOS_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: NACOS_HOST
          resources:
            requests:
              cpu: 250m
              memory: 512Mi
            limits:
              cpu: 1000m
              memory: 1Gi
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: 8084
            initialDelaySeconds: 60
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: 8084
            initialDelaySeconds: 30
            periodSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: warehouse-service
  namespace: erp
spec:
  type: ClusterIP
  ports:
    - port: 8084
      targetPort: 8084
      protocol: TCP
      name: http
  selector:
    app: warehouse-service
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: warehouse-service-hpa
  namespace: erp
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: warehouse-service
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
