apiVersion: apps/v1
kind: Deployment
metadata:
  name: waybill-service
  namespace: erp
  labels:
    app: waybill-service
    version: v1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: waybill-service
  template:
    metadata:
      labels:
        app: waybill-service
        version: v1
    spec:
      containers:
        - name: waybill-service
          image: erp/waybill-service:1.0.0-SNAPSHOT
          ports:
            - containerPort: 8086
              name: http
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: "k8s"
            - name: DB_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: DB_HOST
            - name: DB_PORT
              value: "3306"
            - name: DB_NAME
              value: "erp_db"
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: erp-db-secret
                  key: DB_USER
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: erp-db-secret
                  key: DB_PASSWORD
            - name: REDIS_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: REDIS_HOST
            - name: REDIS_PORT
              value: "6379"
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: erp-redis-secret
                  key: REDIS_PASSWORD
            - name: NACOS_HOST
              valueFrom:
                configMapKeyRef:
                  name: erp-config
                  key: NACOS_HOST
            - name: NACOS_PORT
              value: "8848"
          resources:
            requests:
              memory: "256Mi"
              cpu: "100m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: 8086
            initialDelaySeconds: 60
            periodSeconds: 30
            timeoutSeconds: 10
          readinessProbe:
            httpGet:
              path: /actuator/health
              port: 8086
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: waybill-service
  namespace: erp
spec:
  type: ClusterIP
  ports:
    - port: 8086
      targetPort: 8086
      protocol: TCP
      name: http
  selector:
    app: waybill-service
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: waybill-service-hpa
  namespace: erp
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: waybill-service
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
