---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: opsdata-api
spec:
  selector:
    matchLabels:
      app: opsdata-api
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      annotations:
        prometheus.io/path: /metrics
        prometheus.io/port: "8000"
        prometheus.io/scrape: "true"
      labels:
        app: opsdata-api
    spec:
      imagePullSecrets:
      - name: regcred
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: beta.kubernetes.io/arch
                operator: In
                values:
                - amd64      
      containers:
      - env:
        - name: DB_PASS
          valueFrom:
            secretKeyRef:
              key: mariadb-password
              name: opsdata-mariadb-galera
              optional: false
        - name: JWT_SECRET_KEY
          valueFrom:
            secretKeyRef:
              key: jwt-secret
              name: opsdata
              optional: false
        - name: DB_HOST
          valueFrom:
            configMapKeyRef:
              key: db-host
              name: opsdata
              optional: false
        - name: DB_PORT
          valueFrom:
            configMapKeyRef:
              key: db-port
              name: opsdata
              optional: false
        - name: DB_NAME
          valueFrom:
            configMapKeyRef:
              key: db-name
              name: opsdata
              optional: false
        - name: DB_USER
          valueFrom:
            configMapKeyRef:
              key: db-user
              name: opsdata
              optional: false
        image: a1-harbor.support.tools/opsdata/api:BUILD_NUMBER
        imagePullPolicy: IfNotPresent
        name: opsdata-api
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 8000
            scheme: HTTP
          periodSeconds: 2
          successThreshold: 1
          timeoutSeconds: 2
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 8000
            scheme: HTTP
          periodSeconds: 2
          successThreshold: 2
          timeoutSeconds: 2
