apiVersion: apps/v1
kind: Deployment
metadata:
  name: elasticsearch-data
  labels:
    app: elasticsearch
    role: data
spec:
  replicas: 2
  selector:
    matchLabels:
      app: elasticsearch
      role: data
  template:
    metadata:
      labels:
        app: elasticsearch
        role: data
    spec:
      serviceAccount: elasticsearch
      initContainers:
        - name: init-sysctl
          image: busybox:1.27.2
          command:
            - sysctl
            - -w
            - vm.max_map_count=262144
          securityContext:
            privileged: true
      containers:
        - name: es-data
          image: quay.io/pires/docker-elasticsearch-kubernetes:6.2.3
          env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: "CLUSTER_NAME"
              value: "cota-k8s"
            - name: NODE_MASTER
              value: "false"
            - name: NODE_INGEST
              value: "false"
            - name: HTTP_ENABLE
              value: "false"
            - name: ES_JAVA_OPTS
              value: -Xms256m -Xmx256m
            - name: AZURE_ACCOUNT_NAME
              valueFrom:
                secretKeyRef:
                  name: azure-storage
                  key: AZURE_ACCOUNT_NAME
            - name: AZURE_ACCOUNT_KEY
              valueFrom:
                secretKeyRef:
                  name: azure-storage
                  key: AZURE_ACCOUNT_KEY
            - name: AZURE_BUCKET_NAME
              value: elasticsearch
            - name: ES_PLUGINS_INSTALL
              value: "repository-azure"
          ports:
            - containerPort: 9300
              name: transport
              protocol: TCP
          livenessProbe:
            tcpSocket:
              port: transport
            initialDelaySeconds: 20
            periodSeconds: 10
          volumeMounts:
            - mountPath: /entrypoint
              name: entrypoint
      volumes:
        - name: entrypoint
          configMap:
            name: es-entrypoint
            items:
              - key: docker-entrypoint.sh
                path: docker-entrypoint.sh
