apiVersion: apps/v1
kind: Deployment
metadata:
  name: report-service
  namespace: erp
  labels:
    app: report-service
    version: v1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: report-service
  template:
    metadata:
      labels:
        app: report-service
        version: v1
    spec:
      containers:
        - name: report-service
          image: erp-registry.cn-hangzhou.cr.aliyuncs.com/erp/report-service:1.0.0
          imagePullPolicy: Always
          ports:
            - containerPort: 8084
              name: http
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: "prod"
            - name: EXPORT_BASE_PATH
              value: "/data/exports"
            - name: JAVA_OPTS
              value: "-Xms512m -Xmx1024m -XX:+UseG1GC -XX:MaxGCPauseMillis=200"
            - name: NACOS_HOST
              value: "nacos"
            - name: NACOS_PORT
              value: "8848"
          resources:
            requests:
              memory: "512Mi"
              cpu: "250m"
            limits:
              memory: "1024Mi"
              cpu: "1000m"
          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
          volumeMounts:
            - name: exports-volume
              mountPath: /data/exports
            - name: log-volume
              mountPath: /var/log/report-service
      volumes:
        - name: exports-volume
          persistentVolumeClaim:
            claimName: exports-pvc
        - name: log-volume
          emptyDir: {}
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchLabels:
                    app: report-service
                topologyKey: kubernetes.io/hostname
---
apiVersion: v1
kind: Service
metadata:
  name: report-service
  namespace: erp
spec:
  type: ClusterIP
  ports:
    - port: 8084
      targetPort: 8084
      protocol: TCP
      name: http
  selector:
    app: report-service
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: exports-pvc
  namespace: erp
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi
  storageClassName: nfs
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: report-service-hpa
  namespace: erp
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: report-service
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
