---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-master
  namespace: logging
  labels:
    component: elasticsearch
    role: master
spec:
  selector:
    matchLabels:
      component: elasticsearch
      role: master
  serviceName: elasticsearch-master
  replicas: 1 # Change this to 3 to have High-Availability
  template:
    metadata:
      labels:
        component: elasticsearch
        role: master
    spec:
      initContainers:
      - name: init-sysctl
        image: busybox:1.27.2
        command:
        - sysctl
        - -w
        - vm.max_map_count=262144
        securityContext:
          privileged: true
      containers:
      - name: es-master
        image: carlosedp/docker-elasticsearch-kubernetes:6.6.0
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: CLUSTER_NAME
          value: myesdb
        - name: NUMBER_OF_MASTERS
          value: "1" # Change this to 2 to have High-Availability
        - name: NODE_MASTER
          value: "true"
        - name: NODE_INGEST
          value: "false"
        - name: NODE_DATA
          value: "false"
        - name: ES_JAVA_OPTS
          value: -Xms512m -Xmx512m
        - name: PROCESSORS
          valueFrom:
            resourceFieldRef:
              resource: limits.cpu
        resources:
          requests:
            cpu: 1
          limits:
            cpu: 1
        ports:
        - containerPort: 9300
          name: transport
        - containerPort: 9200
          name: http
        livenessProbe:
          tcpSocket:
            port: transport
          initialDelaySeconds: 120
          periodSeconds: 10
        volumeMounts:
        - name: elasticsearch-master
          mountPath: /data
        - name: config
          mountPath: /elasticsearch/config/elasticsearch.yml
          subPath: elasticsearch.yml
      volumes:
      - name : config
        configMap:
          name: es-configmap
  volumeClaimTemplates:
  - metadata:
      name: elasticsearch-master
    spec:
      accessModes: [ ReadWriteOnce ]
      resources:
        requests:
          storage: 2Gi
