k8s搭建elasticsearch 8

  • Post author:
  • Post category:技术
  • Post comments:0评论

yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: elasticsearch-pre
  namespace: efk
spec:
  selector:
    matchLabels:
      component: elasticsearch-pre
  template:
    metadata:
      labels:
        component: elasticsearch-pre
    spec:
      containers:
      - name: elasticsearch-pre
        image: <换你自己的仓库>/elasticsearch:8.12.2
        env:
        - name: discovery.type
          value: single-node
        ports:
        - containerPort: 9200
          name: rest
          protocol: TCP
        - containerPort: 9300
          name: java
          protocol: TCP
        volumeMounts:
        - name: localtime
          mountPath: /etc/localtime
        - name: data-persistent-storage-pre  #挂载部署目录
          mountPath: /usr/share/elasticsearch/data
          subPath: data
        - name: data-persistent-storage-pre  #挂载部署目录
          mountPath: /usr/share/elasticsearch/config      # 第一次启动,改为config_bak
          subPath: config            # 第一次启动,改为config_bak
        - name: data-persistent-storage-pre  #挂载部署目录
          mountPath: /usr/share/elasticsearch/plugins
          subPath: plugins
        resources:
          requests:
            cpu: 100m
            memory: 8192Mi
        #lifecycle:     # 第一次启动的时候需要,存好以后,改挂载,重启
        #    postStart:
        #      exec:
        #        command:
        #        - /bin/bash
        #        - -c
        #        - cd /usr/share/elasticsearch && cp -R config/* config_bak;
      initContainers:
      - name: volume-permissions
        image: busybox
        securityContext:
          runAsUser: 0
        command:
        - sh
        - -c
        - chown -R 1000:0 /usr/share/elasticsearch/data
        - chown -R 1000:0 /usr/share/elasticsearch/config
        volumeMounts:
        - name: data-persistent-storage-pre  #挂载部署目录
          mountPath: /usr/share/elasticsearch/data
          subPath: data
        - name: data-persistent-storage-pre  #挂载部署目录
          mountPath: /usr/share/elasticsearch/config
          subPath: config
      volumes:
      - name: localtime
        hostPath:
          path: /etc/localtime
      - name: data-persistent-storage-pre
        nfs:
          path: <换你自己的Path>
          server: <换你自己的IP>
---
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch-pre
  namespace: efk
  labels:
    service: elasticsearch-pre
spec:
  type: NodePort
  selector:
    component: elasticsearch-pre
  ports:
  - port: 9200
    targetPort: 9200
    nodePort: <换你自己的端口>
    name: rest
  - port: 9300
    targetPort: 9300
    nodePort: <换你自己的端口>
    name: java

内存调整

在 config/jvm.options.d/ 下建一个 memory.options

-Xms4g
-Xmx4g

处理挂载volume权限的问题

其它服务挂载volume的路径权限问题也可以参考这个解决方案,未挂载时确认路径的原本用户及用户组。

查用户ID,容器内

id
uid=1000(elasticsearch) gid=1000(elasticsearch) groups=1000(elasticsearch),0(root)
cat /etc/group
root:x:0:elasticsearch
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
巴拉巴拉巴拉巴拉

参考

https://blog.csdn.net/windywolf301/article/details/136227389

0 0 votes
文章评分
订阅
提醒
guest
0 评论
最旧
最新 得票最多