apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-data
  labels:
    app: elasticsearch
    component: elasticsearch
spec:
  selector:
    matchLabels:
      component: elasticsearch
      role: data
  serviceName: es-transport
  replicas: 2
  template:
    metadata:
      labels:
        component: elasticsearch
        http: disabled
        role: data
    spec:
      securityContext:
        runAsUser: 185
        fsGroup: 185
      containers:
      - name: es-data
        image: raaftech/elasticsearch:latest
        imagePullPolicy: Always
        env:
        - name: ES_ALLOW_MMAPFS
          value: "false"
        - name: ES_CLUSTER_NAME
          value: "es-cluster"
        - name: ES_DISCOVERY_SERVICE
          value: "es-transport"
        - name: ES_INDEX_AUTO_CREATE
          value: ".kibana*,.logstash*,.management*,.monitoring*,.security*,.triggered_watches*,.watcher-history*,.watches*"
        - name: ES_INDEX_STORE_TYPE
          value: "niofs"
        - name: ES_NODE_DATA
          value: "true"
        - name: ES_NODE_INGEST
          value: "false"
        - name: ES_NODE_MASTER
          value: "false"
        - name: ES_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: PROCESSORS
          valueFrom:
            resourceFieldRef:
              resource: limits.cpu
        resources:
          requests:
            cpu: 1
            memory: 8Gi
          limits:
            cpu: 2
            memory: 8Gi
        ports:
        - containerPort: 9200
          name: http
        - containerPort: 9300
          name: transport
        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 30
          periodSeconds: 60
          successThreshold: 1
          tcpSocket:
            port: transport
          timeoutSeconds: 3
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /_cluster/health
            port: http
            scheme: HTTP
          initialDelaySeconds: 30
          periodSeconds: 60
          successThreshold: 1
          timeoutSeconds: 6
        volumeMounts:
        - name: storage
          mountPath: /elasticsearch/data
  volumeClaimTemplates:
  - metadata:
      name: storage
      annotations:
        pv.beta.kubernetes.io/gid: "185"
    spec:
      storageClassName: glusterfs-storage-block
      accessModes: [ ReadWriteOnce ]
      resources:
        requests:
          storage: 40Gi
