# version: '3.7'
# k8s namespace network
---
apiVersion: v1
kind: Service
metadata:
  name: es
  namespace: PROJECT_NAMESPACE
  labels:
    app: es
spec:
  ports:
  - name: es
    port: 9200
    targetPort: 9200
    nodePort: 39200
    protocol: TCP
  selector:
    app: es
  type: NodePort
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es
  namespace: PROJECT_NAMESPACE
  labels:
    app: es
    k8s-app: es
spec:
  selector:
    matchLabels:
      app: es
  serviceName: es
  replicas: 1
  #revisionHistoryLimit: 5
  template:
    metadata:
      labels:
        app: es
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - name: es-container
        #image: registry.edoc2.com:5000/edoc2v5/elasticsearch:prod620-v6.7.1.12
        image: ELASTICSEARCH_IMAGES
        imagePullPolicy: IfNotPresent
        env:
        - name: node.name
          value: "es"
        - name: ES_JAVA_OPTS
          value: "-Xmx8g -Xms8g"
        envFrom:
        - configMapRef:
            name: menvfile
        volumeMounts:
          - mountPath: /esdata
            name: owner-es-volume
          - mountPath: /esbackup
            name: es-dbbackup-volume
        ports:
        - containerPort: 9200
          name: esport
          protocol: TCP
      restartPolicy: Always
      volumes:
        - name: owner-es-volume
          hostPath:
            path: ES_DATA_PATH
            type: DirectoryOrCreate
        - name: es-dbbackup-volume
          hostPath:
            path: ES_BACKUP_DATA_PATH
            type: DirectoryOrCreate
      nodeSelector:
        "node.labels.nodelabels": Middleware
