apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: elasticsearch
    component: master
    release: efk
  name: efk-elasticsearch
  namespace: efk
spec:
  podManagementPolicy: Parallel
  replicas: 6
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: elasticsearch
      component: master
      release: efk
  serviceName: efk-elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
        component: master
        release: efk
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - podAffinityTerm:
              labelSelector:
                matchLabels:
                  app: elasticsearch
                  component: master
                  release: efk
              topologyKey: kubernetes.io/hostname
            weight: 1
      securityContext:
        fsGroup: 1000
      containers:
      - env:
        - name: ES_JAVA_OPTS
          value: -Djava.net.preferIPv4Stack=true -Xms4096m -Xmx4096m
        - name: cluster.name
          value: efk-cluster
        - name: discovery.zen.minimum_master_nodes
          value: "2"
        - name: discovery.zen.ping.unicast.hosts
          value: efk-elasticsearch
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        - name: PROCESSORS
          valueFrom:
            resourceFieldRef:
              divisor: "0"
              resource: limits.cpu
        image: docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
        imagePullPolicy: IfNotPresent
        name: efk-elasticsearch
        ports:
        - containerPort: 9300
          name: transport
          protocol: TCP
        - containerPort: 9200
          name: http
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /_cluster/health?local=true
            port: 9200
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 1
        resources:
          requests:
            cpu: 250m
            memory: 512Mi
        securityContext:
          allowPrivilegeEscalation: true
          capabilities: {}
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/data
          name: data
      dnsPolicy: ClusterFirst
      initContainers:
      - command:
        - sysctl
        - -w
        - vm.max_map_count=262144
        image: busybox
        imagePullPolicy: Always
        name: sysctl
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      restartPolicy: Always
      schedulerName: default-scheduler
      serviceAccount: efk-elasticsearch
      serviceAccountName: efk-elasticsearch
      terminationGracePeriodSeconds: 30
      volumes:
      - name: data
  updateStrategy:
    type: OnDelete
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 53Gi
