apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elasticsearch
  namespace: data
  labels:
    app: elasticsearch
spec:
  serviceName: elasticsearch
  replicas: 1 # single node cluster
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      initContainers:
        - name: init-sysctl
          image: busybox:1.27.2
          command: ["sysctl", "-w", "vm.max_map_count=262144"]
          securityContext:
            privileged: true
        - name: init-chown
          image: busybox:1.27.2
          command: ["/bin/sh"]
          args: ["-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
          securityContext:
            privileged: true
          volumeMounts:
            - name: es-data
              mountPath: /usr/share/elasticsearch/data
      containers:
        - name: elasticsearch
          image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
          imagePullPolicy: IfNotPresent
          env:
            - name: "discovery.type"
              value: "single-node"
            - name: "cluster.name"
              value: "apk8s"
            - name: "transport.host"
              value: "127.0.0.1"
            - name: "ES_JAVA_OPTS"
              value: "-Xms512m -Xmx512m"
            - name: "http.host"
              value: "0.0.0.0"
            - name: "http.port"
              value: "9200"
            - name: "http.cors.allow-origin"
              value: "http://localhost:1358"
            - name: "http.cors.enabled"
              value: "true"
            - name: "http.cors.allow-headers"
              value: "X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization"
            - name: "http.cors.allow-credentials"
              value: "true"
          ports:
            - containerPort: 9200
              name: http-es
            - containerPort: 9300
              name: tcp-es
          volumeMounts:
            - name: es-data
              mountPath: /usr/share/elasticsearch/data
  volumeClaimTemplates:
    - metadata:
        name: es-data
      spec:
        storageClassName: rook-ceph-block
        accessModes: [ ReadWriteOnce ]
        resources:
          requests:
            storage: 50Gi