Skip to content

k8s上的es无法安装分词器插件 #1076

@yancy-hong

Description

@yancy-hong

使用ECK安装的es。

k8s部分配置文件:

initContainers:
  - name: install-plugins
    securityContext:
      privileged: true
      runAsUser: 0
    command:
      - sh
      - -c
      - |
        bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.12.2

pod init失败,部分describe pod:

Back-off restarting failed container install-plugins in pod elastic-search-es-default-1_elastic

改配置不自动安装分词器,并重新部署Pod:

initContainers:
  - name: install-plugins
    securityContext:
      privileged: true
      runAsUser: 0
    command:
      - sh
      - -c
      - |
        echo "hello"

kubectl exec 进入Pod,手动安装分词器:

bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.12.2

报错:

Exception in thread "main" java.nio.file.FileSystemException: 
     /usr/share/elasticsearch/config/analysis-ik: Operation not permitted

即使在k8s的配置里为config/analysis-ik添加权限也还是报这个错:

initContainers:
  - name: install-plugins
    securityContext:
      privileged: true
      runAsUser: 0
    command:
      - sh
      - -c
      - |
        mkdir -p config/analysis-ik
        chmod -R 777 config/analysis-ik
        bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.12.2

完整k8s配置:

apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
  name: elastic-search
  namespace: elastic
spec:
  version: 8.12.2
  nodeSets:
    - name: default
      count: 2
      config:
        node.store.allow_mmap: false
        node.roles: ["master", "data", "ingest"]
      volumeClaimTemplates:
        - metadata:
            name: elasticsearch-data
          spec:
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 20Gi
            storageClassName: sc-es
      podTemplate:
        spec:
          containers:
            - name: elasticsearch
              resources:
                requests:
                  memory: 8Gi
                  cpu: 4
                limits:
                  memory: 8Gi
                  cpu: 4
          initContainers:
            - name: install-plugins
              securityContext:
                privileged: true
                runAsUser: 0
              command:
                - sh
                - -c
                - |
                  bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.12.2

  transport:
    service:
      metadata:
        name: elastic
      spec:
        type: NodePort

sc-es storageClass内容:

apiVersion: storage.k8s.io/v1
kind: StorageClass
provisioner: nfs.csi.k8s.io
metadata:
  name: sc-es
allowVolumeExpansion: true
reclaimPolicy: Retain
parameters:
  server: 10.10.10.110
  share: /nfs/elastic/search

nfs目录权限:

ls -ld /nfs/elastic/search/
drwxrwxrwx 6 root root 4096 Sep 14 12:03 /nfs/elastic/search/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions