cloud
cloud-native
云原生与 kubernetes
部署中间件
部署 ElasticSearch(8.x)

部署 ElasticSearch(8.x)

ES 8.7

部署说明:通过 nodeSelector 固定到 worker3 节点上。并使用 worker3 上的原生文件系统目录 /.data

部署文件说明

  1. 通过环境变量指定 JVM 大小, ES 密码等
  2. 通过 config 定制 elasticsearch.yml 的配置, 比如 0.0.0.0 外部网络访问
  3. 有使用 LoadBalancer 类型的 Service, 通过 externalIPs 指定外部 IP
  4. 通过 hostPath 挂载宿主机的目录, 用于持久化数据提升IO性能
  5. 部署于 middleware 命名空间
  6. 镜像使用 registry.cn-hongkong.aliyuncs.com/jansora/elasticsearch:8.7.0, 拷贝自官方镜像,无改动
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elasticsearch-1
  namespace: middleware
spec:
  selector:
    matchLabels:
      app: elasticsearch-1
  replicas: 1
  template:
    metadata:
      labels:
        app: elasticsearch-1
    spec:
      nodeSelector:
        worker: worker3
      containers:
        - name: elasticsearch-1
          image: registry.cn-hongkong.aliyuncs.com/jansora/elasticsearch:8.7.0
          imagePullPolicy: IfNotPresent
          env:
            - name: ES_JAVA_OPTS
#              value: "-Xms1024m -Xmx1024m "
#              value: "-Xms2048m -Xmx2048m "
#              value: "-Xms1536m -Xmx1536m "
              value: "-Xms4096m -Xmx4096m "
            - name: ES_PORT
              value: "9200"
            - name: ELASTIC_PASSWORD
              value: "xxxxxx"
          ports:
            - containerPort: 9200
          volumeMounts:
            - name: host-path
              subPath: 'elasticsearch/8.7.0/data'
              mountPath: '/usr/share/elasticsearch/data'
            - name: host-path
              subPath: 'elasticsearch/8.7.0/config/analysis-ik'
              mountPath: '/usr/share/elasticsearch/config/analysis-ik'
            - name: host-path
              subPath: 'elasticsearch/8.7.0/plugins'
              mountPath: '/usr/share/elasticsearch/plugins'
            - name: host-path
              subPath: 'elasticsearch/8.7.0/logs'
              mountPath: '/usr/share/elasticsearch/logs'
            - name: config-volume
              mountPath: /usr/share/elasticsearch/config/elasticsearch.yml # 具体路径请参考官方文档
              subPath: elasticsearch.yml
      volumes:
        - name: config-volume
          configMap:
            name: elasticsearch-config
        - name: host-path
          hostPath:
            type: DirectoryOrCreate
            path: /.data/
  serviceName: elasticsearch-service
---
 
# 创建 Service 由 kubernetes 来对多个 broker 做负载均衡
apiVersion: v1
kind: Service
metadata:
  labels:
    app: elasticsearch-1
  name: elasticsearch-1-service
  namespace: middleware
spec:
  type: LoadBalancer
  externalIPs:
    - 192.168.36.9
  ports:
    - port: 9200
      protocol: TCP
  selector:
    app: elasticsearch-1
 
 
---
 
 
# 创建 configmap
apiVersion: v1
kind: ConfigMap
metadata:
  name: elasticsearch-config
  namespace: middleware
data:
  elasticsearch.yml: |
    cluster.initial_master_nodes: ["elasticsearch-1-0"]
    xpack.security.enabled: false
    network.host: 0.0.0.0