#######################################################################
# Kubernetes StatefulSet for the Elasticsearch single node setup
#
# This is a simple Elasticsearch deployment. You should follow best
# practices if ever you want to go in production with this setup.
#
# The https://github.com/pires/kubernetes-elasticsearch-cluster
# repository is a nice example!
#######################################################################

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: wazuh-elasticsearch
  namespace: wazuh
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wazuh-elasticsearch
  serviceName: wazuh-elasticsearch
  template:
    metadata:
      labels:
        app: wazuh-elasticsearch
      name: wazuh-elasticsearch
    spec:
      # Set the wazuh-elasticsearch volume permissions so the elasticsearch user can use it!
      initContainers:
        - name: volume-mount-hack
          image: busybox
          resources:
            requests:
              cpu: 50m
              memory: 128Mi
            limits:
              cpu: 100m
              memory: 256Mi
          command:
            - sh
            - '-c'
            - 'chown -R 1000:1000 /usr/share/elasticsearch/data'
          volumeMounts:
            - name: wazuh-elasticsearch
              mountPath: /usr/share/elasticsearch/data
      containers:
        - name: wazuh-elasticsearch
          image: 'docker.elastic.co/elasticsearch/elasticsearch:6.4.0'
          resources:
            requests:
              cpu: 500m
              memory: 1Gi
            limits:
              cpu: 1
              memory: 2Gi
          env:
            - name: ES_JAVA_OPTS
              value: '-Xms1024m -Xmx1024m'
            - name: bootstrap.memory_lock
              value: 'false'
            - name: cluster.name
              value: wazuh
            - name: network.host
              value: 0.0.0.0
            - name: node.name
              value: node-1
          volumeMounts:
            - name: wazuh-elasticsearch
              mountPath: /usr/share/elasticsearch/data
          ports:
            - containerPort: 9200
              name: es-rest
            - containerPort: 9300
              name: es-nodes
  volumeClaimTemplates:
    - metadata:
        name: wazuh-elasticsearch
        namespace: wazuh
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: gp2-encrypted-retained
        resources:
          requests:
            storage: 30Gi
