kubernetes 安装elasticsearch集群

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、创建一个持久化存储卷,以保存 Elasticsearch 数据。可以使用 Kubernetes 的各种存储解决方案(如 hostPath、nfs、awsElasticBlockStore 等)。

2、创建一个 ConfigMap,以配置 Elasticsearch 实例所需的设置。ConfigMap 可包括 Elasticsearch 配置文件中的任何自定义设置(这里我没处理)。

3、创建一个 StatefulSet,作为 Elasticsearch 集群的部署方式。StatefulSet 可以确保每个 Elasticsearch 节点都有一个唯一的名称和网络标识符,并依次启动和关闭节点。

4、在 StatefulSet 中指定容器映像,以及与该容器关联的存储和其他配置。

5、使用 Service 对外公开 Elasticsearch 集群。Service 可以路由到集群中的任何节点,以实现负载均衡和服务发现。

猜你喜欢

转载自blog.csdn.net/helenyqa/article/details/130008044