foreword

The last article wrote about the installation of ElasticSearch and Kibana on Helm3 , but found that the ik Chinese word segmentation was not installed, so I will basically share with you how to install elasticsearch with ik word segmentation.

operate

Before the operation, I would like to thank smokelee's article: k8s brainless series (11) - install ElasticSearch to the cluster and set up Chinese word segmentation , my article is also based on this article.

Steps:
1. Download the ik word segmentation package
2. Make a docker image with ik word segmentation
3. Modify the values.yaml file of bitnami/elasticsearch and use the docker image just made
4. Install elasticsearch and kibana
5. Use develop tools in kibana to verify whether ik is installed successfully

1. Download the ik and pinyin word segmentation packages

The following is the package address, you can choose the appropriate version to download.

 https://github.com/medcl/elasticsearch-analysis-ik/releases
https://github.com/medcl/elasticsearch-analysis-pinyin/releases

2. Make a docker image with ik and pinyin word segmentation

After the download is complete, arrange the folders as shown in the figure below
image.png

Then, let's write the Dockerfile

 FROM docker.io/bitnami/elasticsearch:8.2.2-debian-11-r0
COPY ik /opt/bitnami/elasticsearch/plugins/ik

Note that here we use the docker image of bitnami/elasticsearch 6c8c7a3109f664f8b5f5a90a339be66b---, the version number is 8.2.2-debian-11-r0 , you can refer to this address to select the appropriate version.

Next, we execute the following commands in sequence in the docker directory to create a docker image containing the ik and pingyin word segmentation.

 docker login --username=xxx registry.cn-hangzhou.aliyuncs.com
docker build -t registry.cn-hangzhou.aliyuncs.com/com-seaurl/seaurl-elasticsearch:x.x.x  .
docker push registry.cn-hangzhou.aliyuncs.com/com-seaurl/seaurl-elasticsearch:x.x.x

I use Alibaba Cloud for the above address. You can set it as your own mirror center address according to the specification, so we have completed the production of the docker image.

3. Modify the values.yaml file of bitnami/elasticsearch and use the docker image just made

According to the explanation in the previous article, let's configure the values.yaml file

 global:
  storageClass: "alicloud-cnfs-nas"
  elasticsearch:
    service:
      name: elasticsearch
      ports:
        restAPI: 9200
  kibanaEnabled: false
image:
  registry: registry.cn-hangzhou.aliyuncs.com
  repository: com-seaurl/seaurl-elasticsearch
  # 这里的x.x.x就是你刚才制作docker镜像的版本号:x.x.x
  tag: x.x.x
sysctlImage:
  enabled: false
plugins: analysis-icu
service:
  type: NodePort
master:
  replicaCount: 1
data:
  replicaCount: 1
coordinating:
  replicaCount: 1
ingest:
  replicaCount: 1

4. Install elasticsearch and kibana

Execute the following command to install elasticsearch,

 helm install -f test-values.yaml test-elasticsearch bitnami/elasticsearch --namespace

output:

 elasticsearch
NAME: test-elasticsearch
LAST DEPLOYED: Mon Jul 11 21:44:14 2022
NAMESPACE: elasticsearch
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: elasticsearch
CHART VERSION: 18.2.9
APP VERSION: 8.2.2

-------------------------------------------------------------------------------
 WARNING

    Elasticsearch requires some changes in the kernel of the host machine to
    work as expected. If those values are not set in the underlying operating
    system, the ES containers fail to boot with ERROR messages.

    To check whether the host machine meets the requirements, run the command
    below:

      kubectl logs --namespace elasticsearch $(kubectl get --namespace elasticsearch \
        pods -l app=elasticsearch,role=master -o jsonpath='{.items[0].metadata.name}') \
        elasticsearch

    You can adapt the Kernel parameters on you cluster as described in the
    official documentation:

      https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster

    As an alternative, you can specify "sysctlImage.enabled=true" to use a
    privileged initContainer to change those settings in the Kernel:

      helm upgrade --namespace elasticsearch test-elasticsearch bitnami/elasticsearch --set sysctlImage.enabled=true

    Note that this requires the ability to run privileged containers, which is likely not
    the case on many secure clusters. To cover this use case, you can also set some parameters
    in the config file to customize the default settings:

      https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-store.html
      https://www.elastic.co/guide/en/cloud-on-k8s/master/k8s-virtual-memory.html

    For that, you can place the desired parameters by using the "config" block present in the values.yaml

** Please be patient while the chart is being deployed **

  Elasticsearch can be accessed within the cluster on port 9200 at test-elasticsearch.elasticsearch.svc.cluster.local

  To access from outside the cluster execute the following commands:

    export NODE_PORT=$(kubectl get --namespace elasticsearch -o jsonpath="{.spec.ports[0].nodePort}" services test-elasticsearch)
    export NODE_IP=$(kubectl get nodes --namespace elasticsearch -o jsonpath="{.items[0].status.addresses[0].address}")
    curl http://$NODE_IP:$NODE_PORT/

Then, we get the ip and port through the above command

 # 获取port
kubectl get --namespace elasticsearch -o jsonpath="{.spec.ports[0].nodePort}" services test-elasticsearch

# 获取ip
kubectl get nodes --namespace elasticsearch -o jsonpath="{.items[0].status.addresses[0].address}"

After obtaining the ip and port of elasticsearch, let's install kibana and execute the following command:

 helm install -f test-values.yaml test-kibana bitnami/kibana --namespace elasticsearch

output:

 NAME: test-kibana
LAST DEPLOYED: Mon Jul 11 21:52:08 2022
NAMESPACE: elasticsearch
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: kibana
CHART VERSION: 10.1.9
APP VERSION: 8.2.2

** Please be patient while the chart is being deployed **

1. Get the application URL by running these commands:
  export NODE_PORT=$(kubectl get --namespace elasticsearch -o jsonpath="{.spec.ports[0].nodePort}" services test-kibana)
  export NODE_IP=$(kubectl get nodes --namespace elasticsearch -o jsonpath="{.items[0].status.addresses[0].address}")
  echo http://$NODE_IP:$NODE_PORT

WARNING: Kibana is externally accessible from the cluster but the dashboard does not contain authentication mechanisms. Make sure you follow the authentication guidelines in your Elastic stack.
+info https://www.elastic.co/guide/en/elasticsearch/reference/current/setting-up-authentication.html

Then, we get the ip and port through the above command

 # 获取port
kubectl get --namespace elasticsearch -o jsonpath="{.spec.ports[0].nodePort}" services test-kibana

# 获取ip
kubectl get nodes --namespace elasticsearch -o jsonpath="{.items[0].status.addresses[0].address}"

5. Use develop tools in kibana to verify whether ik is installed successfully

After installing elasticsearch and kibana, we try to open Dev Tools in Chrome to verify whether the ik word segmentation package is installed successfully, so we enter the following code and execute:

 POST _analyze
{
  "analyzer": "ik_smart",
  "text": "我喜欢你"
}

image.png

success! ! !

Summarize

In the Dockerfile 8.2.2-debian-11-r0 don't write the wrong version number, I was struggling for a week because of this mistake, don't make the same mistake as me!

 FROM docker.io/bitnami/elasticsearch:8.2.2-debian-11-r0

quote

k8s brainless series (11) - install ElasticSearch to the cluster and set up Chinese word segmentation


Awbeci
3.1k 声望213 粉丝

Awbeci