kubernetes install elasticsearch cluster

yaml


---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: search-elasticsearch
  namespace: test
  labels:
    app: search-elasticsearch
    name: search-elasticsearch
spec:
  serviceName: search-elasticsearch
  replicas: 3
  selector:
    matchLabels:
      app: search-elasticsearch
  template:
    metadata:
      labels:
        app: search-elasticsearch
    spec:
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app
                      operator: In
                      values:
                        - search-elasticsearch
                topologyKey: kubernetes.io/hostname

      initContainers:
        - name: increase-vm-max-map
          image: busybox
          imagePullPolicy: IfNotPresent
          command: [ "sysctl", "-w", "vm.max_map_count=262144" ]
          securityContext:
            privileged: true
        - name: increase-fd-ulimit
          image: busybox
          imagePullPolicy: IfNotPresent
          command: [ "sh", "-c", "ulimit -n 65536" ]
          securityContext:
            privileged: true
      containers:
        - name: elastic-search
          image: elasticsearch:7.6.2
          command:
            - /bin/bash
            - '-c'
            - |-
              #!/bin/bash
              ulimit -l unlimited
              echo ulimit
              exec su elasticsearch /usr/local/bin/docker-entrypoint.sh
          resources:
            limits:
              memory: 2700Mi
            requests:
              memory: 2700Mi
          ports:
            - name: transport
              containerPort: 9300
              protocol: TCP
            - name: restful
              containerPort: 9200
              protocol: TCP
          env:
            - name: node.name
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: cluster.name
              value: search-elasticsearch-cluster
            - name: discovery.seed_hosts
              value: "search-elasticsearch-0.search-elasticsearch,search-elasticsearch-1.search-elasticsearch,search-elasticsearch-2.search-elasticsearch"
            - name: cluster.initial_master_nodes
              value: 'search-elasticsearch-0,search-elasticsearch-1,search-elasticsearch-2'
            - name: bootstrap.memory_lock
              value: 'true'
            - name: ES_JAVA_OPTS
              value: '-Xms2048m -Xmx2048m'
            - name: network.host
              value: "0.0.0.0"
            - name: node.max_local_storage_nodes
              value: "3"
          securityContext:
            privileged: true

          volumeMounts:
            - name: cloud-train-pvc
              mountPath: /usr/share/elasticsearch/data
              subPath: elasticsearch/data/
            - name: cloud-elasticsearch-pvc
              mountPath: /usr/share/elasticsearch/plugins/
              subPath: elasticsearch/plugins/

      volumes:
        - name: cloud-elasticsearch-pvc
          persistentVolumeClaim:
            claimName: elasticsearch-pvc
            # 先创建好


---

apiVersion: v1
kind: Service
metadata:
  name: search-elasticsearch
  namespace: test
  labels:
    app: search-elasticsearch
spec:
  type: ClusterIP
  selector:
    app: search-elasticsearch
  ports:
    - port: 9200
      name: restful
      targetPort: 9200
      protocol: TCP
    - name: transport
      port: 9300
      targetPort: 9300
      protocol: TCP

1. Create a persistent storage volume to save Elasticsearch data. Various storage solutions for Kubernetes (such as hostPath, nfs, awsElasticBlockStore, etc.) can be used.

2. Create a ConfigMap to configure the required settings for the Elasticsearch instance. A ConfigMap can include any custom settings in the Elasticsearch configuration file (which I'm not dealing with here).

3. Create a StatefulSet as the deployment method of the Elasticsearch cluster. A StatefulSet ensures that each Elasticsearch node has a unique name and network identifier, and starts and shuts down nodes sequentially.

4. Specify the container image in the StatefulSet, as well as the storage and other configurations associated with the container.

5. Use the Service to expose the Elasticsearch cluster to the outside world. Service can be routed to any node in the cluster for load balancing and service discovery.

Guess you like

Origin blog.csdn.net/helenyqa/article/details/130008044