# Written by Mutlu Polatcan
# 18.11.2019
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: hadoop-slave
  labels:
    app: hadoop
    unit: slave
spec:
  serviceName: hadoop
  replicas: 3
  selector:
    matchLabels:
      app: hadoop
      unit: slave
  template:
    metadata:
      name: hadoop-slave
      labels:
        app: hadoop
        unit: slave
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: app
                    operator: In
                    values:
                      - hadoop
                  - key: unit
                    operator: In
                    values:
                      - master
                      - slave
              topologyKey: kubernetes.io/hostname
      initContainers:
        - name: hadoop-slave-init
          imagePullPolicy: Always
          image: mpolatcan/hadoop:3.2.1-java8
          command:
            - /bin/bash
          args:
            - -c
            - $(INIT_SCRIPT)
          envFrom:
            - configMapRef:
                name: hadoop-init
          volumeMounts:
            - mountPath: /hadoop-state
              name: hadoop-slave-volume
      containers:
        - name: hadoop-slave
          image: mpolatcan/hadoop:3.2.1-java8
          imagePullPolicy: Always
          envFrom:
            - configMapRef:
                name: hadoop-slave
          volumeMounts:
            - mountPath: /home/hduser
              name: hadoop-slave-volume
          livenessProbe:
            tcpSocket:
              port: 9864
            initialDelaySeconds: 15
            periodSeconds: 2
            failureThreshold: 3
          readinessProbe:
            tcpSocket:
              port: 9864
            initialDelaySeconds: 15
            periodSeconds: 2
            failureThreshold: 3
      securityContext:
        fsGroup: 1000
      restartPolicy: Always
  volumeClaimTemplates:
    - metadata:
        name: hadoop-slave-volume
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: gce-pd-hdd
        resources:
          requests:
            storage: 50Gi