apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: lh-es-single-node
  namespace: logharbour
spec:
  serviceName: elasticsearch
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      containers:
      - name: elasticsearch
        #image: elasticsearch:8.11.1
        image: bitnami/elasticsearch:8.11.1       
        #resources:
         #   limits:
          #    cpu: 1000m
           # requests:
            #  cpu: 100m
        ports:
        - containerPort: 9200
          name: rest
          protocol: TCP
        #- containerPort: 9300
         # name: inter-node
          #protocol: TCP
        #lifecycle:
         # postStart:
          #  exec:
           #   command:
            #  - "/bin/sh"
             # - "-c"
              #- |
               # chown -R elasticsearch:elasticsearch /var/lib/elasticsearch
                #chown -R 1001:1001 /usr/share/elasticsearch/data
                #find /usr/share/elasticsearch/data -type d -exec chmod 775 {} \;
                #find /usr/share/elasticsearch/data -type d -exec chmod 664 {} \;
                #bin/elasticsearch-users useradd remiges -p rem@cloud9
        volumeMounts:
        - name: data
          #mountPath: /usr/share/elasticsearch/data
          mountPath: /bitnami/elasticsearch/data
        #- name: config
        #  mountPath: /usr/share/elasticsearch/config
        #env:
         # - name: cluster.name
          #  value: k8s-logs
          #- name: node.name
           # value: es-single-node
          #- name: discovery.type
           # value: single-node
          #- name: ES_JAVA_OPTS
           # value: "-Xms256m -Xmx256m"
          #- name: "ELASTICSEARCH_USERNAME"
           # value: "remiges"
          #- name: "ELASTICSEARCH_PASSWORD"
           # value: "rem@cloud9"
      nodeSelector:
        name: node-1
  volumeClaimTemplates:
  - metadata:
      name: data
      labels:
        app: elasticsearch
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: standard
      resources:
        requests:
          storage: 1Gi

---

kind: Service
apiVersion: v1
metadata:
  name: elasticsearch
  namespace: logharbour
  labels:
    app: elasticsearch
spec:
  selector:
    app: elasticsearch
  #type: NodePort
  ports:
    - port: 9200
      #targetPort: 9200
      name: rest
      #nodePort: 30016
    - port: 9300
      name: inter-node

---

apiVersion: v1
kind: PersistentVolume
metadata:
  name: lh-data-es
  namespace: logharbour
spec:
  capacity:
    storage: 1Gi
#  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  storageClassName: standard
  hostPath:
    path: /kra-data/data/dev/elasticsearch-data
  persistentVolumeReclaimPolicy: Retain
