apiVersion: apps/v1
kind: Deployment
metadata:
  name: chat-api
  namespace: juwan
  labels:
    app: chat-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chat-api
  template:
    metadata:
      labels:
        app: chat-api
    spec:
      imagePullSecrets:
        - name: registry-creds
      containers:
      - name: chat-api
        image: registry.juwan.xhttp.zip/juwan/chat-api:latest
        ports:
        - name: http
          containerPort: 8888
        - name: ws
          containerPort: 8889
        - name: wt
          containerPort: 8443
          hostPort: 8443
          protocol: UDP
        - name: metrics
          containerPort: 4001
        env:
          - name: MONGO_PASSWORD
            valueFrom:
              secretKeyRef:
                name: chat-mongodb-app-user-password
                key: password
          - name: MONGO_URI
            value: "mongodb://app-user:$(MONGO_PASSWORD)@chat-mongodb-0.chat-mongodb-svc.juwan.svc.cluster.local:27017/juwan_chat?replicaSet=chat-mongodb&authSource=admin"
          - name: MONGO_DATABASE
            value: juwan_chat
          - name: REDIS_HOST
            value: chat-redis-master.juwan
          - name: REDIS_PORT
            value: "6379"
          - name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: chat-redis
                key: password
          - name: JWT_SECRET_KEY
            valueFrom:
              secretKeyRef:
                name: jwt-secret
                key: secret-key
          - name: CHAT_WT_CERT_FILE
            value: "/etc/certs/tls.crt"
          - name: CHAT_WT_KEY_FILE
            value: "/etc/certs/tls.key"
        volumeMounts:
        - name: certs
          mountPath: /etc/certs
          readOnly: true
        resources:
          requests:
            cpu: 10m
            memory: 32Mi
          limits:
            memory: 512Mi
      volumes:
        - name: certs
          secret:
            secretName: chat-wt-tls

---
apiVersion: v1
kind: Service
metadata:
  name: chat-api-svc
  namespace: juwan
spec:
  ports:
    - name: http
      port: 8888
      targetPort: 8888
    - name: ws
      port: 8889
      targetPort: 8889
    - name: wt
      port: 8443
      targetPort: 8443
      protocol: UDP
    - name: metrics
      port: 4001
      targetPort: 4001
  selector:
    app: chat-api
