apiVersion: v1
kind: Service
metadata:
  name: spark-live-dashboard-driver
  labels:
    app.kubernetes.io/name: spark-analytics
    app.kubernetes.io/part-of: nowchess
spec:
  clusterIP: None
  selector:
    app: spark-live-dashboard
  ports:
    - name: driver
      port: 37007
      targetPort: 37007
    - name: blockmanager
      port: 37777
      targetPort: 37777
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: spark-live-dashboard
  labels:
    app.kubernetes.io/name: spark-analytics
    app.kubernetes.io/part-of: nowchess
spec:
  replicas: 0
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: spark-live-dashboard
  template:
    metadata:
      labels:
        app: spark-live-dashboard
        app.kubernetes.io/name: spark-analytics
        app.kubernetes.io/part-of: nowchess
    spec:
      serviceAccountName: spark-analytics
      securityContext:
        fsGroup: 185
      imagePullSecrets:
        - name: ghcr-pull-secret
      containers:
        - name: spark-driver
          image: ghcr.io/now-chess/now-chess-systems/analytics:latest
          command:
            - /opt/spark/bin/spark-submit
            - --master
            - spark://spark-master:7077
            - --conf
            - spark.executor.instances=1
            - --conf
            - spark.executor.cores=1
            - --conf
            - spark.executor.memory=512m
            - --conf
            - spark.driver.memory=512m
            - --conf
            - spark.driver.host=spark-live-dashboard-driver
            - --conf
            - spark.driver.port=37007
            - --conf
            - spark.blockManager.port=37777
            - --class
            - de.nowchess.analytics.LiveDashboardJob
            - file:///app/analytics.jar
            - /spark-checkpoint
          env:
            - name: NOWCHESS_JDBC_URL
              valueFrom:
                secretKeyRef:
                  name: ncs-db-secrets
                  key: STORE_DB_URL
            - name: NOWCHESS_DB_USER
              valueFrom:
                secretKeyRef:
                  name: ncs-db-secrets
                  key: STORE_DB_USER
            - name: NOWCHESS_DB_PASS
              valueFrom:
                secretKeyRef:
                  name: ncs-db-secrets
                  key: STORE_DB_PASSWORD
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: "1"
              memory: 1Gi
          volumeMounts:
            - name: spark-checkpoint
              mountPath: /spark-checkpoint
      volumes:
        - name: spark-checkpoint
          persistentVolumeClaim:
            claimName: spark-streaming-checkpoint
