apiVersion: apps/v1
kind: Deployment
metadata:
  name: gateway
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gateway
      version: "v1"
  template:
    metadata:
      labels:
        app: gateway
        version: "v1"
    spec:
      initContainers:
        - name: init-ds
          image: busybox
          command:
            - '/bin/sh'
            - '-c'
            - |
                while true
                do
                  rt=$(nc -z -w 1 mongodb 27017)
                  if [ $? -eq 0 ]; then
                    echo "DB is UP"
                    break
                  fi
                  echo "DB is not yet reachable;sleep for 10s before retry"
                  sleep 10
                done
      containers:
      - name: gateway-app
        image: gcr.io/dega-224221/gateway
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: prod
        - name: SPRING_CLOUD_CONSUL_HOST
          value: consul.default.svc.cluster.local
        - name: SPRING_CLOUD_CONSUL_PORT
          value: "8500"
        - name: SPRING_DATA_MONGODB_DATABASE
          value: gateway
        - name: SPRING_DATA_MONGODB_URI
          value: "mongodb://mongodb-0.mongodb.default:27017"
        - name: SPRING_DATA_JEST_URI
          value: http://elasticsearch.default.svc.cluster.local:9200
        - name: SPRING_SLEUTH_PROPAGATION_KEYS
          value: "x-request-id,x-ot-span-context"
        - name: JAVA_OPTS
          value: " -Xmx256m -Xms256m"
        resources:
          requests:
            memory: "256Mi"
            cpu: "500m"
          limits:
            memory: "512Mi"
            cpu: "1"
        ports:
        - name: http
          containerPort: 8080
        readinessProbe:
          httpGet:
            path: /management/health
            port: http
          initialDelaySeconds: 20
          periodSeconds: 15
          failureThreshold: 6
        livenessProbe:
          httpGet:
            path: /management/health
            port: http
          initialDelaySeconds: 120
