apiVersion: apps/v1
kind: Deployment
metadata:
  name: email-api
  namespace: juwan
  labels:
    app: email-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: email-api
  template:
    metadata:
      labels:
        app: email-api
    spec:
      imagePullSecrets:
        - name: registry-creds
      containers:
      - name: email-api
        image: registry.juwan.xhttp.zip/juwan/email-api:latest
        ports:
        - name: http
          containerPort: 8888
        - name: metrics
          containerPort: 4001
        env:
          - name: REDIS_HOST
            value: user-redis-master.juwan
          - name: REDIS_PORT
            value: "6379"
          - name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: user-redis
                key: password
          - name: KAFKA_BROKER
            value: "juwan-kafka-0.juwan-kafka.redpanda:9092"
        resources:
          requests:
            cpu: 10m
            memory: 32Mi
          limits:
            memory: 512Mi

---
apiVersion: v1
kind: Service
metadata:
  name: email-api-svc
  namespace: juwan
spec:
  ports:
    - name: http
      port: 8888
      targetPort: 8888
    - name: metrics
      port: 4001
      targetPort: 4001
  selector:
    app: email-api

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: email-mq
  namespace: juwan
  labels:
    app: email-mq
spec:
  replicas: 1
  selector:
    matchLabels:
      app: email-mq
  template:
    metadata:
      labels:
        app: email-mq
    spec:
      imagePullSecrets:
        - name: registry-creds
      containers:
      - name: email-mq
        image: registry.juwan.xhttp.zip/juwan/email-mq:latest
        ports:
        - name: metrics
          containerPort: 4001
        env:
          - name: KAFKA_BROKER
            value: "juwan-kafka-0.juwan-kafka.redpanda:9092"
          - name: EMAIL_SMTP_HOST
            valueFrom:
              secretKeyRef:
                name: email-smtp
                key: host
          - name: EMAIL_SMTP_PORT
            valueFrom:
              secretKeyRef:
                name: email-smtp
                key: port
          - name: EMAIL_SMTP_USERNAME
            valueFrom:
              secretKeyRef:
                name: email-smtp
                key: username
          - name: EMAIL_SMTP_PASSWORD
            valueFrom:
              secretKeyRef:
                name: email-smtp
                key: password
          - name: EMAIL_FROM_ADDRESS
            valueFrom:
              secretKeyRef:
                name: email-smtp
                key: from-address
          - name: EMAIL_FROM_NAME
            valueFrom:
              secretKeyRef:
                name: email-smtp
                key: from-name
          - name: EMAIL_REPLY_TO
            valueFrom:
              secretKeyRef:
                name: email-smtp
                key: reply-to
        resources:
          requests:
            cpu: 10m
            memory: 32Mi
          limits:
            memory: 512Mi

---
apiVersion: v1
kind: Service
metadata:
  name: email-mq-svc
  namespace: juwan
spec:
  ports:
    - name: metrics
      port: 4001
      targetPort: 4001
  selector:
    app: email-mq
