kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: restfulapi-amd64
  namespace: default
  labels:
     run: dlwsrestfulapi
spec:
  selector:
    matchLabels:
      restfulapi-node: pod
  template:
    metadata:
      name: restfulapi-amd64
      labels:
        restfulapi-node: pod
        app: restfulapi
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/path: "/metrics"
        prometheus.io/port: "5000"
    spec:
      
      nodeSelector:
        restfulapi: active
        archType: amd64
      hostNetwork: true
      initContainers:
      #During this Pod's initialization, check that postgres service is up and running before starting this pod
      - name: check-postgres-ready
        image: harbor.apulis.cn:8443/aiarts_v1.5.0_rc8/apulistech/busybox:v1.28

        command: ['sh', '-c', "until nc -vz 192.168.2.163 5432; do echo 'Waiting for postgres service'; sleep 2; done;"]

      containers:
      - name: restfulapi
        image: harbor.apulis.cn:8443/aiarts_v1.5.0_rc8/apulistech/dlworkspace_restfulapi2:v1.5.0-rc8

        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /usr/bin/kubectl
          name: kubectl-binary
          readOnly: true
        - mountPath: /root/.kube/config
          name: kubeconfig
          readOnly: true
        - mountPath: /etc/resolv.conf
          name: resolv
        - mountPath: /RestfulAPI/config.yaml
          name: apiconfig
          subPath: config.yaml
        - mountPath: /var/log/apache2
          name: log
        - mountPath: /dlwsdata/work
          name: aiplatform-app-data-pvc
          subPath: work/
        - mountPath: /home
          name: aiplatform-app-data-pvc
          subPath: work/
        - mountPath: /dlwsdata/storage
          name: aiplatform-model-data-pvc
        ports:
        - containerPort: 5000
          hostPort: 5000
          name: main
      volumes:
      - name: apiconfig
        configMap:
          name: restful-cm
      - name: kubectl-binary
        hostPath:
          path: /opt/kube/bin/kubectl

      - name: kubeconfig
        hostPath:
          path: /root/.kube/config
      - name: resolv
        hostPath:
          path: /etc/resolv.conf
      - name: log
        hostPath:
          path: /var/log/restfulapi
      - name: aiplatform-app-data-pvc
        persistentVolumeClaim:
          claimName: aiplatform-app-data-pvc
      - name: aiplatform-model-data-pvc
        persistentVolumeClaim:
          claimName: aiplatform-model-data-pvc
      tolerations:
      - key: CriticalAddonsOnly
        operator: Exists
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
