apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elastic
  namespace: TARGET_K8S_NAMESPACE
  labels:
    app: elastic
spec:
  serviceName: "elastic"
  replicas: 1
  selector:
    matchLabels:
      app: elastic
  template:
    metadata:
      labels:
        app: elastic
    spec:
      priorityClassName: napptive-high-priority
      containers:
        - name: elastic
          image: elasticsearch:7.11.2
          resources:
            requests:
              memory: "8Gi"
              cpu: "2"
            limits:
              memory: "8Gi"
              cpu: "2"
          imagePullPolicy: "IfNotPresent"
          ports:
            - containerPort: 9200
              name: http
            - containerPort: 9300
              name: transport
          volumeMounts:
            - name: storage
              mountPath: /data
            - name: config
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
              subPath: elasticsearch.yml
              readOnly: true
          env:
            - name: node.name
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: ES_JAVA_OPTS
              value: -Xms4g -Xmx4g
            - name: cluster.initial_master_nodes
              value: elastic-0
      initContainers:
        - name: fix-permissions
          image: busybox
          command: ["sh", "-c", "chown -R 1000:1000 /data"]
          securityContext:
            privileged: true
          volumeMounts:
            - name: storage
              mountPath: /data
        - name: increase-vm-max-map
          image: busybox
          command: ["sysctl", "-w", "vm.max_map_count=262144"]
          securityContext:
            privileged: true
        - name: increase-fd-ulimit
          image: busybox
          command: ["sh", "-c", "ulimit -n 65536"]
          securityContext:
            privileged: true
      volumes:
        - name: config
          configMap:
            defaultMode: 0644
            name: elastic-config
  volumeClaimTemplates:
    - metadata:
        name: storage
      spec:
        accessModes:
          - ReadWriteOnce
        storageClassName: "managed-premium"
        resources:
          requests:
            storage: 5Gi
