---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-data-hot
  labels:
    app: es
    role: data
    type: hot
spec:
  replicas: 5
  serviceName: es-discovery
  podManagementPolicy: OrderedReady
  updateStrategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: es
      role: data
      type: hot
  template:
    metadata:
      labels:
        app: es
        role: data
        type: hot
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: app
                operator: In
                values:
                - es
      initContainers:
      - name: init-data
        image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0-amd64
        imagePullPolicy: "IfNotPresent"
        command:
        - /bin/bash
        - -c
        - chown -R elasticsearch. /usr/share/elasticsearch
        securityContext:
          runAsUser: 0
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: data
      - name: init-sysctl
        image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0-amd64
        imagePullPolicy: IfNotPresent
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
      containers:
      - name: es-data
        image: docker.elastic.co/elasticsearch/elasticsearch:7.8.0-amd64
        imagePullPolicy: Always
        securityContext:
          capabilities:
            add:
            - IPC_LOCK
            - SYS_RESOURCE
        ports:
        - containerPort: 9200
          name: http
        - containerPort: 9300
          name: transport
        env:
        - name:  "ES_JAVA_OPTS"
          value: "-Xms8g -Xmx8g"
        - name: "cluster.name"
          value: "es"
        - name: "node.name"
          value: "${HOSTNAME}"
        - name:  "bootstrap.memory_lock"
          value: "false"
        - name: "discovery.seed_hosts"
          value: "es-discovery"
        - name: "cluster.initial_master_nodes"
          value: "es-master-0,es-master-1,es-master-2"
        - name: "discovery.zen.ping_timeout"
          value: "5s"
        - name: "node.master"
          value: "false"
        - name: "node.data"
          value: "true"
        - name: "node.attr.box_type"
          value: "hot"
        - name: "node.ingest"
          value: "false"
        resources:
          limits:
            cpu: "4"
            memory: 16Gi
          requests:
            cpu: "4"
            memory: 16Gi
        livenessProbe:
          httpGet:
            path: /_cluster/health?local=true
            port: 9200
          initialDelaySeconds: 60
          timeoutSeconds: 5
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /_cluster/health?local=true
            port: 9200
          initialDelaySeconds: 60
          timeoutSeconds: 5
          periodSeconds: 20
        volumeMounts:
        - name: data
          mountPath: /usr/share/elasticsearch/data
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      storageClassName: data
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 500Gi