apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-master
  namespace: devops
  labels:
    component: es
    role: master
spec:
  replicas: 1 #3
  serviceName: "es-master-ss"
  selector:
    matchLabels:
      component: es
  #------------------------------------
  #NOTE:
  #------------------------------------
  #podManagementPolicy: "Parallel"
  template:
    metadata:
      labels:
        component: es
        role: master
    spec:
      securityContext:
        fsGroup: 1000
      containers:
      - name: es-master
        securityContext:
          privileged: true
          capabilities:
            add:
              - IPC_LOCK
        image: elasticsearch:7.4.2
#        imagePullPolicy: Always
        env:
        #------------------------------------
        #NOTE:
        #------------------------------------
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: "NUMBER_OF_MASTERS"
          value: "1"
        - name: NODE_MASTER
          value: "true"
        - name: NODE_INGEST
          value: "true"
        - name: NODE_DATA
          value: "true"
#        - name: HTTP_ENABLE
#          value: "false"
#        - name: MAX_LOCAL_STORAGE_NODES
#          value: "10"
        - name: XPACK_SECURITY_ENABLED
          value: "false"
        - name: "ES_JAVA_OPTS"
          #value: "-Xms4g -Xmx4g -Des.enforce.bootstrap.checks=true"
          value: "-Des.enforce.bootstrap.checks=true"
        - 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"
        - name: discovery.type
          value: "single-node"
        - name: cluster.name
          value: demo
        - name: node.name
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
#        - name: discovery.seed_hosts
#          value: "es-cluster-0.elasticsearch,es-cluster-1.elasticsearch,es-cluster-2.elasticsearch"
#        - name: cluster.initial_master_nodes
#          value: "es-cluster-0,es-cluster-1,es-cluster-2"
        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: 2000m
#            memory: 8Gi
#          limits:
#            cpu: 4000m
#            memory: 8Gi
        readinessProbe:
          tcpSocket:
            port: 9300
          timeoutSeconds: 1
          successThreshold: 1
        livenessProbe:
          tcpSocket:
            port: 9300
          periodSeconds: 60
          timeoutSeconds: 1
          successThreshold: 1
      volumes:
      - name: log-volume
        emptyDir: {}
      - name: es-config-volume
        configMap:
          name: es-config
      initContainers:
        - name: init-sysctl
          image: busybox
          command: ["sysctl", "-w", "vm.max_map_count=262144"]
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
#  volumeClaimTemplates:
#  - metadata:
#      name: data-volume
#      annotations:
#        volume.beta.kubernetes.io/storage-class: thick-disk
##        volume.beta.kubernetes.io/storage-class: gp2
#    spec:
#      accessModes: [ "ReadWriteOnce" ]
#      resources:
#        requests:
#          storage: 1Gi

