apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  namespace: default
spec:
  replicas: 7
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
      - name: api
        image: fabricioveronez/pedelogo-catalogo:v1.0.0
        resources:
          limits:
            memory: "256Mi"
            cpu: "200m"
        ports:
        - containerPort: 80
        imagePullPolicy: IfNotPresent
        envFrom:
            - configMapRef:
                  name: api-configmap

        env:
        - name: Mongo__User
          valueFrom:
            secretKeyRef:
                key: MONGO_INITDB_ROOT_USERNAME
                name: mongodb-secret

        - name: Mongo__Password
          valueFrom:
                secretKeyRef:
                    key: MONGO_INITDB_ROOT_PASSWORD
                    name: mongodb-secret
      affinity:
        podAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 1 # Pelo menos um pod ficará no mesmo node que está o POD/Deployment Mongodb
              podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - "mongodb"

        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 2
              podAffinityTerm:
                topologyKey: kubernetes.io/hostname
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - "api"
