apiVersion: apps/v1
kind: Deployment
metadata:
  name: spark-master
  labels:
    app.kubernetes.io/name: spark-master
    app.kubernetes.io/part-of: nowchess
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: spark-master
  template:
    metadata:
      labels:
        app.kubernetes.io/name: spark-master
        app.kubernetes.io/part-of: nowchess
    spec:
      # Prevent K8s from injecting SPARK_MASTER_PORT=tcp://... env vars (Docker-link
      # style). Spark master parses SPARK_MASTER_PORT as an integer and crashes.
      enableServiceLinks: false
      containers:
        - name: spark-master
          image: apache/spark:4.0.3-scala2.13-java17-ubuntu
          command:
            - /opt/spark/bin/spark-class
            - org.apache.spark.deploy.master.Master
          ports:
            - name: cluster
              containerPort: 7077
            - name: webui
              containerPort: 8080
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: 500m
              memory: 512Mi
          volumeMounts:
            - name: spark-events
              mountPath: /spark-events
      volumes:
        - name: spark-events
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: spark-master
  labels:
    app.kubernetes.io/name: spark-master
    app.kubernetes.io/part-of: nowchess
spec:
  selector:
    app.kubernetes.io/name: spark-master
  ports:
    - name: cluster
      port: 7077
      targetPort: cluster
    - name: webui
      port: 8080
      targetPort: webui
  type: ClusterIP
