apiVersion: apps/v1
kind: Deployment
metadata:
    name: elasticsearch
spec:
    replicas: 1
    selector:
        matchLabels:
            app: elasticsearch
    strategy:
        type: Recreate
    template:
        metadata:
            labels:
                app: elasticsearch
        spec:
            securityContext:
                fsGroup: 1000

            initContainers:
                - name: init-sysctl
                  image: busybox
                  command: ['/bin/sh', '-c']
                  args:
                      - sysctl -w vm.max_map_count=262144
                      - ulimit -l unlimited
                  imagePullPolicy: IfNotPresent
                  securityContext:
                      privileged: true
                      capabilities:
                          add:
                              - IPC_LOCK
                              - SYS_RESOURCE
            containers:
                - env:
                      - name: ES_JAVA_OPTS
                        value: -Xms512m -Xmx512m
                      - name: bootstrap.memory_lock
                        value: 'false'
                      - name: cluster.name
                        value: docker-cluster
                  image: docker.elastic.co/elasticsearch/elasticsearch:6.6.1
                  #   livenessProbe:
                  #       httpGet:
                  #           path: /_cluster/health
                  #           port: 9200
                  #       failureThreshold: 3
                  #       periodSeconds: 30
                  #       timeoutSeconds: 30
                  name: elasticsearch
                  ports:
                      - containerPort: 9200
                  resources:
                      requests:
                          memory: '1Gi'
                          cpu: '200m'
                      limits:
                          memory: '1Gi'
                          cpu: '200m'
                  securityContext:
                      privileged: true
                      capabilities:
                          add:
                              - IPC_LOCK
                              - SYS_RESOURCE
                  volumeMounts:
                      - mountPath: /usr/share/elasticsearch/data
                        name: elasticsearch-persistent-storage

            restartPolicy: Always
            volumes:
                - name: elasticsearch-persistent-storage
                  emptyDir: {}
