apiVersion: apps/v1
kind: Deployment
metadata:
  name: email-consumer
  namespace: juwan
  labels:
    app: email-consumer
spec:
  replicas: 3
  revisionHistoryLimit: 5
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
  selector:
    matchLabels:
      app: email-consumer
  template:
    metadata:
      labels:
        app: email-consumer
    spec:
      serviceAccountName: find-endpoints
      containers:
        - name: email-consumer
#          image: 103.236.53.208:4418/library/email-mq@sha256:a9f76e8f4a17d1c00cefc429962037550e17feebb5cf38b28d360c91c8ba3e68
          image: 103.236.53.208:4418/juwan/email-mq:latest
          imagePullPolicy: Always
          env:
            - name: KAFKA_BROKER
              value: "my-cluster-kafka-bootstrap.kafka:9092"
            - name: EMAIL_SMTP_HOST
              valueFrom:
                secretKeyRef:
                  name: email-smtp-secret
                  key: EMAIL_SMTP_HOST
            - name: EMAIL_SMTP_PORT
              valueFrom:
                secretKeyRef:
                  name: email-smtp-secret
                  key: EMAIL_SMTP_PORT
            - name: EMAIL_SMTP_USERNAME
              valueFrom:
                secretKeyRef:
                  name: email-smtp-secret
                  key: EMAIL_SMTP_USERNAME
            - name: EMAIL_SMTP_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: email-smtp-secret
                  key: EMAIL_SMTP_PASSWORD
            - name: EMAIL_FROM_ADDRESS
              valueFrom:
                secretKeyRef:
                  name: email-smtp-secret
                  key: EMAIL_FROM_ADDRESS
            - name: EMAIL_FROM_NAME
              valueFrom:
                secretKeyRef:
                  name: email-smtp-secret
                  key: EMAIL_FROM_NAME
            - name: EMAIL_REPLY_TO
              valueFrom:
                secretKeyRef:
                  name: email-smtp-secret
                  key: EMAIL_REPLY_TO
          ports:
            - containerPort: 4001
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 50m
              memory: 128Mi
          volumeMounts:
            - name: timezone
              mountPath: /etc/localtime
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai

---
apiVersion: v1
kind: Service
metadata:
  name: email-consumer-svc
  namespace: juwan
  annotations:
    prometheus.io/scrape: "true"
    prometheus.io/port: "4001"
    prometheus.io/path: "/metrics"
spec:
  ports:
    # - port: 8080
    #   targetPort: 8080
    - name: metrics
      port: 4001
      targetPort: 4001
  selector:
    app: email-consumer

---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: email-consumer-hpa-c
  namespace: juwan
  labels:
    app: email-consumer-hpa-c
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: email-consumer
  minReplicas: 1
  maxReplicas: 3
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 80

---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: email-consumer-hpa-m
  namespace: juwan
  labels:
    app: email-consumer-hpa-m
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: email-consumer
  minReplicas: 1
  maxReplicas: 3
  metrics:
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: 80
