# version: '3.7'
# k8s namespace network
apiVersion: apps/v1
#kind: StatefulSet
kind: Deployment
#kind: Pod
metadata:
  name: es
  namespace: edoc2
  labels:
    app: es
    k8s-app: es
  #annotations:
  #  cni.projectcalico.org/ipAddrs: "[\"172.17.85.222\"]"
spec:
  selector:
    matchLabels:
      app: es
  #serviceName: es
  replicas: 1
  revisionHistoryLimit: 5
  template:
    metadata:
      labels:
        app: es
    spec:
      hostname: es
      initContainers:
      - name: increase-vm-max-map
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sysctl", "-w", "vm.max_map_count=655360"]
        securityContext:
          privileged: true
      - name: increase-file-max-map
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sysctl", "-w", "fs.file-max=655360"]
        securityContext:
          privileged: true
      - name: increase-somaxconn-map
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sysctl", "-w", "net.core.somaxconn=38096"]
        securityContext:
          privileged: true
      - name: increase-fd-ulimit
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sh", "-c", "ulimit -n 655360"]
        securityContext:
          privileged: true
      terminationGracePeriodSeconds: 30
      containers:
      - name: es-container
        image: registry.edoc2.com:5000/edoc2v5/elasticsearch:prod660-v7.17.4.1
        imagePullPolicy: IfNotPresent
        env:
        - name: cluster.name
          value: edoc2
        - name: node.name
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: ES_JAVA_OPTS
          value: "-Xmx8g -Xms8g"
        - name: NODE_NAME
          value: "es-node1"
        - name: MODE
          value: "cluster"
        securityContext:
          privileged: true
        volumeMounts:
          - mountPath: /esdata
            name: owner-es-volume
          #- mountPath: /esbackup
          #  name: es-dbbackup-volume
          #- mountPath: /usr/local/elasticsearch-7.17.4/config/elasticsearch.yml
          #  name: esa-conf
          #  subPath: elasticsearch.yml
          - mountPath: /usr/local/elasticsearch-7.17.4/config/jvm.options
            name: esa-jvm
            subPath: jvm.options
          - mountPath: /etc/security/limits.conf
            name: limits-cnf
            subPath: limits.conf
          - mountPath: /usr/local/elasticsearch/plugins/ik/config/IKAnalyzer.cfg.xml
            name: ik
            subPath: IKAnalyzer.cfg.xml
        ports:
        - containerPort: 9200
          name: esport
          protocol: TCP
        - containerPort: 9100
          name: esport9100
          protocol: TCP
        - containerPort: 9300
          name: esport9300
          protocol: TCP
      restartPolicy: Always
      volumes:
        #- name: esa-conf
        #  configMap:
        #    defaultMode: 493
        #    name: es-config
        #    items:
        #      - key: elasticsearch0.yml
        #        path: elasticsearch.yml 
        - name: esa-jvm
          configMap:
            defaultMode: 493
            name: es-config
            items:
              - key: jvm.options
                path: jvm.options
        - name: limits-cnf
          configMap:
            defaultMode: 493
            name: es-config
            items:
              - key: limits.conf
                path: limits.conf
        - name: ik
          configMap:
            defaultMode: 493
            name: es-config
            items:
              - key: IKAnalyzer.cfg.xml
                path: IKAnalyzer.cfg.xml
        #- name: es-dbbackup-volume
        #  hostPath:
        # /home/data/esbackup 备份路径必须是共享存储nas路径(共享存储产研运维定义默认为/home/data/esbackup 无特殊用户要求不做挂载路径调整)
        #    path: /home/data/esbackup
        - name: owner-es-volume
          persistentVolumeClaim:
            claimName: es7-storage-pvc-1
      nodeSelector:
        #"node.labels.nodelabels": Middleware
        "node.es.labels": es-node01
#  volumeClaimTemplates:
#  - metadata:
#      name: owner-es-volume
#    spec:
#      accessModes: [ "ReadWriteOnce" ]
#      storageClassName: "local-es-storage"
#      resources:
#        requests:
#          storage: 200Gi
#  - metadata:
#      name: es-dbbackup-volume
#    spec:
#      accessModes: [ "ReadWriteOnce" ]
#      storageClassName: "backup-es-storage"
#      resources:
#        requests:
#          storage: 200Gi
---
apiVersion: v1
kind: Service
metadata:
  name: es
  namespace: edoc2
  labels:
    app: es
spec:
  #type: ClusterIP
  type: NodePort
  ports:
  - name: es
    port: 9200
    targetPort: 9200
    nodePort: 39200
    protocol: TCP
  - name: es9300
    port: 9300
    targetPort: 9300
    protocol: TCP
  selector:
    app: es
---
apiVersion: v1
kind: Service
metadata:
  name: es0
  namespace: edoc2
  labels:
    app: es0
spec:
  type: NodePort
  ports:
  - name: es0
    port: 9200
    targetPort: 9200
    nodePort: 39199
    protocol: TCP
  selector:
    app: es
