apiVersion: apps/v1
kind: StatefulSet 
metadata:
  name: es-data
  labels:
    role: data
spec:
  serviceName: es-master
  replicas: 1
  selector:
    matchLabels:
      role: data
  template:
    metadata:
      labels:
        role: data
    spec:
      securityContext:
        fsGroup: 1000
      initContainers:
      - name: sysctl-config
        image: busybox
        securityContext: 
          privileged: true
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
      containers:
      - name: es-data
        image: docker.elastic.co/elasticsearch/elasticsearch:6.5.0
        securityContext:
          privileged: true
          runAsUser: 1000
          capabilities:
            add:
            - IPC_LOCK
            - SYS_RESOURCE
        env:
        - name: ES_JAVA_OPTS
          valueFrom:
            configMapKeyRef:
              name: es-data
              key: ES_JAVA_OPTS
        readinessProbe:
          httpGet:
            scheme: HTTP
            path: /_cluster/health?local=true
            port: 9200
        ports:
        - containerPort: 9200
          name: es-http
        - containerPort: 9300
          name: es-transport
        volumeMounts:
        - name: es-data-dir
          mountPath: /usr/share/elasticsearch/data
        - name: es-data-config
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          subPath: elasticsearch.yml
      volumes:
      - name: es-data-config
        configMap:
          name: es-data
          items:
            - key: elasticsearch.yml
              path: elasticsearch.yml
      - name: es-data-dir
        #       persistentVolumeClaim:
        #          claimName: es-data
        emptyDir: {}
            

        


