---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-full
  namespace: logging
  labels:
    component: elasticsearch
    role: full
spec:
  serviceName: elasticsearch-logging
  replicas: 3
  selector:
    matchLabels:
      component: elasticsearch
      role: full
  template:
    metadata:
      labels:
        component: elasticsearch
        role: full
    spec:
      initContainers:
      - name: init-sysctl
        image: busybox:1.27.2
        command:
        - sysctl
        - -w
        - vm.max_map_count=262144
        securityContext:
          privileged: true
      containers:
      - name: es-full
        image: carlosedp/docker-elasticsearch-kubernetes:6.6.0
        resources:
          limits:
            cpu: 2
          requests:
            cpu: 1
            memory: 1Gi
        ports:
        - containerPort: 9300
          name: transport
        - containerPort: 9200
          name: http
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: CLUSTER_NAME
          value: myesdb
        - name: ES_JAVA_OPTS
          value: -Xms1G -Xmx1G
        - name: NETWORK_HOST
          value: _site_,_lo_
        - name: NUMBER_OF_MASTERS
          value: "2"
        - name: PROCESSORS
          valueFrom:
            resourceFieldRef:
              resource: limits.cpu
        #- name: "ES_PLUGINS_INSTALL"
        #  value: "x-pack"
        livenessProbe:
          tcpSocket:
            port: transport
          initialDelaySeconds: 120
          periodSeconds: 10
          timeoutSeconds: 60
        volumeMounts:
        - name: config
          mountPath: /elasticsearch/config/elasticsearch.yml
          subPath: elasticsearch.yml
        - name: storage-full
          mountPath: /data
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: role
                  operator: In
                  values:
                  - full
              topologyKey: kubernetes.io/hostname
      volumes:
      - name : config
        configMap:
          name: es-configmap
  volumeClaimTemplates:
  - metadata:
      name: storage-full
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 20Gi
