You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Helm中挂载整个JSON文件供容器访问?

解决Benthos容器挂载JSON文件的问题

1. 用ConfigMap存储JSON文件

在你的Helm Chart的templates目录下创建configmap.yaml,将example.json的内容存入ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: benthos-json-file
data:
  example.json: |-
    {{ .Files.Get "example.json" | nindent 4 }}

注意:要把example.json放在Helm Chart的根目录(和Chart.yaml同级),这样Helm才能通过.Files.Get读取到文件内容。

2. 在Deployment中挂载ConfigMap到容器

修改Chart里的deployment.yaml,添加卷和挂载配置,把ConfigMap挂载到容器内的指定目录:

spec:
  template:
    spec:
      volumes:
        - name: json-volume
          configMap:
            name: benthos-json-file
      containers:
        - name: benthos
          image: bento/benthos
          # 其他容器配置(端口、环境变量等)
          volumeMounts:
            - name: json-volume
              mountPath: /app/data  # 自定义容器内的挂载路径,确保容器有访问权限
              readOnly: true

3. 更新Benthos的输入配置

将Benthos配置中的文件路径改为容器内的挂载路径,比如:

input:
  file:
    paths: ["/app/data/example.json"]
    codec: lines

如果你的Benthos配置是通过Helm Values管理的,直接在values.yaml里更新对应配置即可。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 03:42:33