EKS自建ElasticSearch8.8+IK分词器

1. 安装ECK Operator

1
$ kubectl apply -f https://download.elastic.co/downloads/eck/2.8.0/operator.yaml

安装后可查看日志

1
2
3
4
5
6
$kubectl -n elastic-system logs -f statefulset.apps/elastic-operator
{"log.level":"info","@timestamp":"2023-06-23T07:58:35.204Z","log.logger":"manager","message":"maxprocs: Updating GOMAXPROCS=1: determined from CPU quota","service.version":"2.8.0+3940cf4d","service.type":"eck","ecs.version":"1.4.0"}
{"log.level":"info","@timestamp":"2023-06-23T07:58:35.205Z","log.logger":"manager","message":"Setting default container registry","service.version":"2.8.0+3940cf4d","service.type":"eck","ecs.version":"1.4.0","container_registry":"docker.elastic.co"}
{"log.level":"info","@timestamp":"2023-06-23T07:58:35.205Z","log.logger":"manager","message":"Setting up scheme","service.version":"2.8.0+3940cf4d","service.type":"eck","ecs.version":"1.4.0"}
{"log.level":"info","@timestamp":"2023-06-23T07:58:35.205Z","log.logger":"manager","message":"Operator configured to manage all namespaces","service.version":"2.8.0+3940cf4d","service.type":"eck","ecs.version":"1.4.0"}
...

2. 打包ElasticSearch+IK Analyzer镜像

准备DockerFile

1
2
3
4
5
6
# https://github.com/elastic/elasticsearch-docker
FROM elasticsearch:8.8.1

# https://github.com/medcl/elasticsearch-analysis-ik/releases
ENV IK_RELEASE=https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.8.1/elasticsearch-analysis-ik-8.8.1.zip
RUN /usr/share/elasticsearch/bin/elasticsearch-plugin install --batch $IK_RELEASE

打包,推送镜像

3. 部署ElasticSearch

准备yaml, 声明es8.8.1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: quickstart
spec:
  version: 8.8.1
  image: xxxxxxxxxxxx.dkr.ecr.ap-southeast-1.amazonaws.com/elastic-ik:8.8.1 #es+ik镜像,这里打进去了
  http:
    service:
      spec:
        type: LoadBalancer
    tls:
      selfSignedCertificate:
        ## 取消默认的tls
        disabled: true
  nodeSets:
  - name: default
    count: 3
    volumeClaimTemplates:
    - metadata:
        name: elasticsearch-data # Do not change this name unless you set up a volume mount for the data path.
      spec:
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 200Gi
        storageClassName: gp2
    config:
      node.store.allow_mmap: false

这里要注意提前安装ebs csi对应的驱动

最后大功告成

1
2
3
$ kubectl get elasticsearch
NAME         HEALTH   NODES   VERSION   PHASE   AGE
quickstart   green    3       8.8.1     Ready   1s