---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es
spec:
  selector:
    matchLabels:
      app: es
  replicas: 3
  serviceName: es
  template:
    metadata:
      labels:
        app: es
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: kubernetes.io/role
                operator: In
                values:
                - agent
            topologyKey: "kubernetes.io/hostname"
      containers:
      - env:
        - name: node.name
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: cluster.initial_master_nodes
          value: es-0,es-1,es-2,
        - name: discovery.seed_hosts
          value: elasticsearch-master-headless
        - name: cluster.name
          value: elasticsearch
        - name: network.host
          value: 0.0.0.0
        - name: ES_JAVA_OPTS
          value: -Xmx16g -Xms16g
        - name: node.data
          value: "true"
        - name: node.ingest
          value: "true"
        - name: node.master
          value: "true"
        name: es
        image: david62243/elasticsearch:7-3node
        imagePullPolicy: Always
      initContainers:
      - command:
        - sysctl
        - -w
        - vm.max_map_count=262144
        image: david62243/elasticsearch:7-3node
        imagePullPolicy: Always
        name: configure-sysctl
        resources: {}
        securityContext:
          privileged: true
          procMount: Default
          runAsUser: 0
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File      
