k8s上集成es集群

vim es.yaml

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-sts-01
spec:
  selector:
    matchLabels:
      app: es
      es-cluster: es01
  serviceName: elasticsearch-svc
  replicas: 1
  template:
    metadata:
      labels:
        app: es
        es-cluster: es01
    spec:
      terminationGracePeriodSeconds: 10
      volumes:
        - name: data-storage
          persistentVolumeClaim:
            claimName: es-nfs-pvc-1
        - name: localtime
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
            type: File
      containers:
        - name: elasticsearch
          image: elasticsearch:7.6.2
          ports:
            - containerPort: 9200
              name: es-cli
            - containerPort: 9300
              name: es-inner
          env:
            - name: cluster.name
              value: es-cluster
            - name: node.name
              value: es01
            - name: cluster.initial_master_nodes
              value: es01,es02,es03
            - name: discovery.seed_hosts
              value: es-svc-inner-02,es-svc-inner-02
            - name: http.cors.enabled
              value: "true"
            - name: http.cors.allow-origin
              value: "*"
          volumeMounts:
            - mountPath: /usr/share/elasticsearch/data
              name: data-storage
            - name: localtime
              mountPath: /etc/localtime
              readOnly: true
  volumeClaimTemplates:
    - metadata:
        name: "data-storage"
      spec:
        resources:
          requests:
            storage: 1G
        accessModes:
        - ReadWriteOnce
        storageClassName: "nfs-storageclass"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-sts-02
spec:
  selector:
    matchLabels:
      app: es
      es-cluster: es02
  serviceName: elasticsearch-svc
  replicas: 1
  template:
    metadata:
      labels:
        app: es
        es-cluster: es02
    spec:
      terminationGracePeriodSeconds: 10
      volumes:
        - name: data-storage
          persistentVolumeClaim:
            claimName: es-nfs-pvc-2
        - name: localtime
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
            type: File
      containers:
        - name: es-02
          image: elasticsearch:7.6.2
          ports:
            - containerPort: 9200
              name: es-cli
            - containerPort: 9300
              name: es-inner
          env:
            - name: cluster.name
              value: es-cluster
            - name: node.name
              value: es02
            - name: cluster.initial_master_nodes
              value: es01,es02,es03
            - name: discovery.seed_hosts
              value: es-svc-inner-01,es-svc-inner-03
            - name: http.cors.enabled
              value: "true"
            - name: http.cors.allow-origin
              value: "*"
          volumeMounts:
            - mountPath: /usr/share/elasticsearch/data
              name: data-storage
            - name: localtime
              mountPath: /etc/localtime
              readOnly: true
  volumeClaimTemplates:
    - metadata:
        name: "data-storage"
      spec:
        resources:
          requests:
            storage: 1G
        accessModes:
        - ReadWriteOnce
        storageClassName: "nfs-storageclass"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: es-sts-03
spec:
  selector:
    matchLabels:
      app: es
      es-cluster: es03
  serviceName: elasticsearch-svc
  replicas: 1
  template:
    metadata:
      labels:
        app: es
        es-cluster: es03
    spec:
      terminationGracePeriodSeconds: 10
      volumes:
        - name: data-storage
          persistentVolumeClaim:
            claimName: es-nfs-pvc-3
        - name: localtime
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
            type: File
      containers:
        - name: es-03
          image: elasticsearch:7.6.2
          ports:
            - containerPort: 9200
              name: es-cli
            - containerPort: 9300
              name: es-iner
          env:
            - name: cluster.name
              value: es-cluster
            - name: node.name
              value: es03
            - name: cluster.initial_master_nodes
            - name: discovery.seed_hosts
              value: es-svc-inner-01,es-svc-inner-02
            - name: http.cors.enabled
              value: "true"
            - name: http.cors.allow-origin
              value: "*"
          volumeMounts:
            - mountPath: /usr/share/elasticsearch/data
              name: data-storage
            - name: localtime
              mountPath: /etc/localtime
              readOnly: true
  volumeClaimTemplates:
    - metadata:
        name: "data-storage"
      spec:
        resources:
          requests:
            storage: 1G
        accessModes:
        - ReadWriteOnce
        storageClassName: "nfs-storageclass"
---
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-svc
  labels:
    app: elasticsearch-svc
spec:
  type: NodePort
  ports:
    - port: 9200
      name: es-cli
      targetPort: 9200
      nodePort: 31920
  selector:
    app: es

---
apiVersion: v1
kind: Service
metadata:
  name: es-svc-inner-01
  labels:
    app: es-svc-inner-01
spec:
  type: ClusterIP
  ports:
    - port: 9300
      name: es-port
  selector:
    es-cluster: es01

---
apiVersion: v1
kind: Service
metadata:
  name: es-svc-inner-02
  labels:
    app: es-svc-inner-02
spec:
  type: ClusterIP
  ports:
    - port: 9300
      name: es-port
  selector:
    es-cluster: es02

---
apiVersion: v1
kind: Service
metadata:
  name: es-svc-inner-03
  labels:
    app: es-svc-inner-03
spec:
  type: ClusterIP
  ports:
    - port: 9300
      name: es-port
  selector:
    es-cluster: es03

  kubectl apply -f es.yaml 即可

你可能感兴趣的:(kubernetes,elasticsearch)