You need to enable JavaScript to run this app. Kubernetes上部署TheHive4集群的application.conf配置问题求助
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes上部署TheHive4集群的application.conf配置问题求助

K8s部署TheHive4集群问题求助

我尝试在K8s上搭建TheHive4集群。查看官方文档后发现,官方提供的部署方案是针对普通服务器环境的,与K8s场景不匹配。此处有一个非官方Helm Chart,但不符合我的需求。
我编写了如下部署清单,已成功在Kubernetes上拉起TheHive4节点,但由于application.conf配置不正确,这些节点并未组成集群。
请问是否有朋友尝试过类似部署、或有相关经验?麻烦分享相关文档或可用的支持方案,帮我完成部署配置。

apiVersion: v1
kind: ConfigMap
metadata:
  name: thehive-config
data:
  application.conf: |
    
    # configuration example using servers not k8s

    akka {
      cluster.enable = on 
      actor {
        provider = cluster
      }
    remote.artery {
      canonical {
        hostname = "<My IP address>"
        port = 2551
      }
    }
    # seed node list contains at least one active node
    cluster.seed-nodes = [
                          "akka://[email protected]<Node 1 IP address>:2551",
                          "akka://[email protected]<Node 2 IP address>:2551",
                          "akka://[email protected]<Node 3 IP address>:2551"
                        ]
    }
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: thehive-claim1
  name: thehive-claim1
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1G
status: {}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  labels:
    io.kompose.service: thehive-claim2
  name: thehive-claim2
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1G
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: thehive
  name: thehive
spec:
  replicas: 3
  selector:
    matchLabels:
      io.kompose.service: thehive
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert
        kompose.version: 1.22.0 (955b78124)
      creationTimestamp: null
      labels:
        io.kompose.service: thehive
    spec:
      containers:
        - args:
            - --no-config
            - --no-config-secret
          image: thehiveproject/thehive4:latest
          name: thehive4
          ports:
            - containerPort: 9000
          resources: {}
          volumeMounts:
            - mountPath: /etc/thehive/application.conf
              subPath: application.conf
              name: config-volume
            - mountPath: /opt/thp/thehive/data
              name: thehive-claim1
            - mountPath: /opt/thp/thehive/index
              name: thehive-claim2
      restartPolicy: Always
      volumes:
        - name: config-volume
          configMap:
            name: thehive-config
        - name: thehive-claim1
          persistentVolumeClaim:
            claimName: thehive-claim1
        - name: thehive-claim2
          persistentVolumeClaim:
            claimName: thehive-claim2
status: {}

配置问题与修正方案

现有配置核心问题

  • 存储配置冲突:两个PVC均为ReadWriteOnce模式且固定名称,3个Pod同时挂载同一RWO卷会触发挂载冲突(绝大多数存储仅支持单节点挂载RWO卷)。
  • 工作负载类型错误:Akka集群需要稳定网络标识配置seed节点,Deployment会导致Pod重启后IP、主机名动态变化,无法固定集群成员。
  • Akka配置不适配K8s网络:remote.artery.canonical.hostname和seed节点列表均使用固定IP,无法适配K8s动态Pod网络。

修正实现

  1. 新增Headless Service,为StatefulSet Pod提供稳定DNS解析。
  2. 将Deployment替换为StatefulSet,通过volumeClaimTemplates为每个Pod自动分配独立RWO存储卷,避免挂载冲突。
  3. 动态注入环境变量生成Akka canonical地址,seed节点列表替换为StatefulSet的稳定Pod DNS地址。

修正后完整配置

# Headless Service 提供Pod DNS解析
apiVersion: v1
kind: Service
metadata:
  name: thehive-headless
  labels:
    app: thehive
spec:
  selector:
    app: thehive
  clusterIP: None
  ports:
    - name: akka
      port: 2551
    - name: http
      port: 9000
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: thehive-config
data:
  application.conf: |
    akka {
      cluster.enable = on
      actor {
        provider = cluster
      }
      remote.artery {
        canonical {
          # 动态生成Pod FQDN,由StatefulSet+Headless Service保证可解析
          hostname = ${?HOSTNAME}."thehive-headless"."${?NAMESPACE}".svc.cluster.local
          port = 2551
        }
      }
      # 3副本配置前2个Pod的稳定DNS作为seed节点即可
      cluster.seed-nodes = [
        "akka://[email protected]thehive-0.thehive-headless.default.svc.cluster.local:2551",
        "akka://[email protected]thehive-1.thehive-headless.default.svc.cluster.local:2551"
      ]
    }
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: thehive
  labels:
    app: thehive
spec:
  replicas: 3
  serviceName: thehive-headless
  selector:
    matchLabels:
      app: thehive
  template:
    metadata:
      labels:
        app: thehive
    spec:
      containers:
        - args:
            - --no-config
            - --no-config-secret
          image: thehiveproject/thehive4:latest
          name: thehive4
          ports:
            - containerPort: 9000
              name: http
            - containerPort: 2551
              name: akka
          env:
            # 注入环境变量供Akka配置动态读取
            - name: HOSTNAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          volumeMounts:
            - mountPath: /etc/thehive/application.conf
              subPath: application.conf
              name: config-volume
            - mountPath: /opt/thp/thehive/data
              name: data
            - mountPath: /opt/thp/thehive/index
              name: index
      volumes:
        - name: config-volume
          configMap:
            name: thehive-config
  # 自动为每个Pod创建独立PVC
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 1G
    - metadata:
        name: index
      spec:
        accessModes: [ "ReadWriteOnce" ]
        resources:
          requests:
            storage: 1G

内容的提问来源于stack exchange,提问作者Abdelwahhab

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.28 20:45:07