apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-data
  namespace: devops
  labels:
    component: es
    role: data
spec:
  podManagementPolicy: "Parallel"
  replicas: 6
  serviceName: "es-data"
  selector:
    matchLabels:
      component: es
  template:
    metadata:
      labels:
        component: es
        role: data
    spec:
      securityContext:
        fsGroup: 1000
      initContainers:
        - name: init-sysctl
          image: busybox
          command: ["sysctl", "-w", "vm.max_map_count=262144"]
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
      containers:
      - name: es-data
        securityContext:
          privileged: true
          capabilities:
            add:
              - IPC_LOCK
        image: docker.elastic.co/es/es:6.2.0
        imagePullPolicy: Always
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: CLUSTER_NAME
          value: "demo"
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: NODE_MASTER
          value: "false"
        - name: NODE_INGEST
          value: "false"
        - name: NODE_DATA
          value: "true"
        - name: HTTP_ENABLE
          value: "false"
        - name: MAX_LOCAL_STORAGE_NODES
          value: "10"
        - name: "ES_JAVA_OPTS"
          value: "-Xms4g -Xmx4g"
        - name: XPACK_SECURITY_ENABLED
          value: "false"
        - name: XPACK_MONITORING_ENABLED
          value: "false"
        - name: XPACK_ML_ENABLED
          value: "false"
        - name: XPACK_GRAPH_ENABLED
          value: "false"
        - name: XPACK_WATCHER_ENABLED
          value: "false"
        ports:
        - containerPort: 9300
          name: transport
          protocol: TCP
        volumeMounts:
        - name: data-volume
          mountPath: /var/lib/es
        - name: log-volume
          mountPath: /var/log/es
        - name: es-config-volume
          mountPath: /usr/share/es/config/es.yml
          subPath: es.yml
        - name: es-config-volume
          mountPath: /usr/share/es/config/log4j2.properties
          subPath: log4j2.properties
        resources:
          requests:
            cpu: 3
            memory: 8Gi
          limits:
            cpu: 3
            memory: 8Gi
        readinessProbe:
          tcpSocket:
            port: 9300
          periodSeconds: 60
          timeoutSeconds: 1
          failureThreshold: 3
        livenessProbe:
          tcpSocket:
            port: 9300
          periodSeconds: 60
          timeoutSeconds: 1
          failureThreshold: 3
      volumes:
      - name: log-volume
        emptyDir: {}
      - name: es-config-volume
        configMap:
          name: es-config
  volumeClaimTemplates:
  - metadata:
      name: data-volume
      annotations:
        volume.beta.kubernetes.io/storage-class: gp2
        pv.beta.kubernetes.io/gid: "1000"
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 100Gi
