apiVersion: apps/v1
kind: Deployment
metadata:
  name: adidas-challenge-subscription-service
  namespace: dev
  labels:
    app: adidas-challenge-subscription-service
spec:
  selector:
    matchLabels:
      app: adidas-challenge-subscription-service
  revisionHistoryLimit: 2
  replicas: 4
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: adidas-challenge-subscription-service
    spec:
      containers:
      - image: adidas-challenge-subscription-service:1.0.0
        imagePullPolicy: Always
        name: adidas-challenge-subscription-api
        livenessProbe:
          exec:
            command:
            - node
            - --version
          initialDelaySeconds: 5
          periodSeconds: 5
        readinessProbe:
          httpGet:
            path: /ping
            port: 3001
          periodSeconds: 3
        resources:
          requests:
            cpu: 400m
            memory: 1024Mi
          limits:
            cpu: 600m
            memory: 1280Mi
        ports:
          - name: http
            containerPort: 3001
        env:
          - name: MONGODB_USER
            valueFrom:
              secretKeyRef:
                name: secret-db
                key: mongo-user
          - name: MONGODB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: secret-db
                key: mongo-password
          - name: MONGODB_DBNAME
            valueFrom:
              secretKeyRef:
                name: secret-db
                key: mongo-dbname
          - name: SECRET
            valueFrom:
              secretKeyRef:
                name: secret-api
                key: jwt-secret
          - name: MONGODB_URI
            valueFrom:
              configMapKeyRef:
                name: adidas-challenge-subscription-service
                key: mongodb-uri
          - name: EMAIL_SERVICE_URL
            valueFrom:
              configMapKeyRef:
                name: adidas-challenge-subscription-service
                key: email-service-url
          - name: MAX_REQUEST_MS_GAP
            valueFrom:
              configMapKeyRef:
                name: adidas-challenge-subscription-service
                key: max-request-ms-gap
      - image: mongodb:latest
        name: adidas-challenge-subscription-mongo
        ports:
          - name: http
            containerPort: 27017
        resources:
          requests:
            cpu: 400m
            memory: 1024Mi
          limits:
            cpu: 600m
            memory: 1280Mi
        volumeMounts:
        - mountPath: /data/db
          name: mongodb
      volumes:
      - name: mongodb
        persistentVolumeClaim:
          claimName: mongodb-pvc
