#<-----------------------------Deploy deployment with k8s------------------->
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: elasticsearch-data
  labels:
    es-name: elasticsearch
    role: data
spec:
  serviceName: elasticsearch-master
  replicas: 2
  template:
    metadata:
      labels:
        es-name: elasticsearch
        role: data
    spec:
      nodeSelector:
        service_type: public
      # Use the stork scheduler to enable more efficient placement of the pods
      initContainers:
      - name: init-sysctl
        image: busybox
        imagePullPolicy: IfNotPresent
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
      containers:
      - name: elasticsearch-data
        securityContext:
          privileged: true
          capabilities:
            add:
              - IPC_LOCK
        image: quay.io/pires/docker-elasticsearch-kubernetes:6.3.2
        imagePullPolicy: Always
        env:
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: "CLUSTER_NAME"
          value: "es-cluster"
        - name: NODE_MASTER
          value: "true"
        - name: NODE_INGEST
          value: "false"
        - name: HTTP_ENABLE
          value: "false"
        - name: "ES_JAVA_OPTS"
          value: "-Xms512m -Xmx512m"
        ports:
        - containerPort: 9300
          name: transport
          protocol: TCP
        volumeMounts:
        - name: es-storage
          mountPath: /data
      volumes:
        - name: es-storage
          hostPath:
            path: /data/apps/es-data/
#<-----------------------------Deploy service with k8s------------------->
apiVersion: v1
kind: Service
metadata:
  name: data-elasticsearch-service
  labels:
    es-name: elasticsearch
    role: data
spec:
  clusterIP: None
  selector:
    es-name: elasticsearch
    role: data
  ports:
  - name: transport
    port: 9300
    protocol: TCP
