EFK 数据在 Pod 重启时丢失

EFK 数据在 Pod 重启时丢失

当 pod 重新启动时,我面临 EFK 设置的数据持久性问题。我已经设置了主 pod、数据 pod 和客户端 pod。

请查看以下配置。

主文件

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: infra
  name: elasticsearch-master
  labels:
    app: elasticsearch
    role: master
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch
      role: master
  template:
    metadata:
      labels:
        app: elasticsearch
        role: master
    spec:
      containers:
      - name: elasticsearch-master
        image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
        env:
        - name: CLUSTER_NAME
          value: elasticsearch
        - name: NODE_NAME
          value: elasticsearch-master
        - name: NODE_LIST
          value: elasticsearch-master,elasticsearch-data,elasticsearch-client
        - name: MASTER_NODES
          value: elasticsearch-master
        - name: "ES_JAVA_OPTS"
          value: "-Xms256m -Xmx256m"
        ports:
        - containerPort: 9300
          name: transport
        volumeMounts:
        - name: config
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          readOnly: true
          subPath: elasticsearch.yml
        - name: elastic-certificates
          mountPath: /usr/share/elasticsearch/config/certs
      volumes:
      - name: config
        configMap:
          name: elasticsearch-master-config
      - name: elastic-certificates
        secret:
          secretName: elastic-certificates
      initContainers:
      - name: increase-vm-max-map
        image: busybox
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
---

数据.yaml

---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  namespace: infra
  name: elasticsearch-data
  labels:
    app: elasticsearch
    role: data
spec:
  serviceName: "elasticsearch-data"
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch-data
      role: data
  template:
    metadata:
      labels:
        app: elasticsearch-data
        role: data
    spec:
      containers:
      - name: elasticsearch-data
        image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
        env:
        - name: CLUSTER_NAME
          value: elasticsearch
        - name: NODE_NAME
          value: elasticsearch-data
        - name: NODE_LIST
          value: elasticsearch-master,elasticsearch-data,elasticsearch-client
        - name: MASTER_NODES
          value: elasticsearch-master
        - name: "ES_JAVA_OPTS"
          value: "-Xms300m -Xmx300m"
        ports:
        - containerPort: 9300
          name: transport
        volumeMounts:
        - name: config
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          readOnly: true
          subPath: elasticsearch.yml
        - name: elasticsearch-data-persistent-storage
          mountPath: /usr/share/elasticsearch/data
        - name: elastic-certificates
          mountPath: /usr/share/elasticsearch/config/certs
      volumes:
      - name: config
        configMap:
          name: elasticsearch-data-config
      - name: elastic-certificates
        secret:
          secretName: elastic-certificates
      initContainers:
      - name: fix-permissions
        image: busybox
        command: [ "sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data" ]
        securityContext:
          privileged: true
        volumeMounts:
          - name: elasticsearch-data-persistent-storage
            mountPath: /usr/share/elasticsearch/data
      - name: increase-vm-max-map
        image: busybox
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
  volumeClaimTemplates:
  - metadata:
      name: elasticsearch-data-persistent-storage
      annotations:
        volume.beta.kubernetes.io/storage-class: "gp2"
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: standard
      resources:
        requests:
          storage: 50Gi
---

客户端.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: infra
  name: elasticsearch-client
  labels:
    app: elasticsearch
    role: client
spec:
  replicas: 1
  selector:
    matchLabels:
      app: elasticsearch
      role: client
  template:
    metadata:
      labels:
        app: elasticsearch
        role: client
    spec:
      containers:
      - name: elasticsearch-client
        image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0
        env:
        - name: CLUSTER_NAME
          value: elasticsearch
        - name: NODE_NAME
          value: elasticsearch-client
        - name: NODE_LIST
          value: elasticsearch-master,elasticsearch-data,elasticsearch-client
        - name: MASTER_NODES
          value: elasticsearch-master
        - name: "ES_JAVA_OPTS"
          value: "-Xms256m -Xmx256m"
        ports:
        - containerPort: 9200
          name: client
        - containerPort: 9300
          name: transport
        volumeMounts:
        - name: config
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          readOnly: true
          subPath: elasticsearch.yml
        - name: elastic-certificates
          mountPath: /usr/share/elasticsearch/config/certs
      volumes:
      - name: config
        configMap:
          name: elasticsearch-client-config
      - name: elastic-certificates
        secret:
          secretName: elastic-certificates
      initContainers:
      - name: increase-vm-max-map
        image: busybox
        command: ["sysctl", "-w", "vm.max_map_count=262144"]
        securityContext:
          privileged: true
---

当 pod 重新启动时,会出现集群 UUID 不匹配错误。

The error message indicates that the Elasticsearch node is trying to join a cluster with a different UUID than the one it previously belonged to. This situation typically occurs when there are inconsistencies in the cluster configuration or data paths.

尝试将持久卷添加到主 pod,但由于数据节点无法识别主 pod,因此出现错误。

如果能得到帮助我们将非常感激。

答案1

这是我(部分)编写的一个小脚本,可以帮助您解决这个问题:

#!/bin/bash

# Create a persistent volume claim (PVC) for the data node
kubectl apply -f - <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: elasticsearch-data-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
EOF

# Update the data node configuration to use the PVC
kubectl patch statefulset elasticsearch-data -p='{"spec":{"volumeClaimTemplates":[{"metadata":{"name":"elasticsearch-data-persistent-storage"},"spec":{"accessModes":["ReadWriteOnce"],"resources":{"requests":{"storage":"50Gi"}}}}]}}'

# Verify the data node configuration
kubectl get statefulset elasticsearch-data -o yaml

# Verify the PVC status
kubectl get pvc elasticsearch-data-pvc -o yaml

它为数据节点创建持久卷声明,然后更新数据节点配置以使用 PVC,然后验证配置和 PVC 状态。

您必须在正确的命名空间中运行此脚本(infra在您的情况下),并根据您的需要调整存储和访问模式具体要求。

非常意识到这个脚本只是一个建议,我没有测试过,所以你应该在非生产环境将其应用到您的生产集群。

相关内容