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

AWS EKS集群中通过Helm部署Prometheus后配置告警规则出现YAML转JSON错误的问题排查

解决Prometheus Helm Chart values.yaml中告警规则配置的YAML解析错误

你遇到的error converting YAML to JSON问题,核心原因是YAML语法使用错误:在配置alerting_rules.yml时,你错误地用大括号{}包裹了多行的告警规则内容,这不符合YAML的规范,导致Helm无法正确解析配置。

问题根源

YAML中,key: {}表示一个空的映射结构,但如果要在这个映射下添加嵌套的子元素(比如groups),不能直接把内容放在大括号里,而是要去掉大括号,通过缩进的方式来定义层级关系。你之前的写法混合了YAML映射的简写语法和多行嵌套结构,触发了解析错误。

正确的配置示例

示例1:InstanceDown告警规则

serverFiles:
  ## Alerts configuration ##
  Ref: https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/
  alerting_rules.yml:
    groups:
    - name: Instances
      rules:
      - alert: InstanceDown
        expr: up == 0
        for: 5m
        labels:
          severity: page
        annotations:
          description: '{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes.'
          summary: 'Instance {{ $labels.instance }} down'

示例2:PodRestarted告警规则

serverFiles:
  ## Alerts configuration ##
  Ref: https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/
  alerting_rules.yml:
    groups:
    - name: pod restarted
      rules:
      - alert: PodRestarted
        expr: job:rate(kube_pod_container_status_restarts_total[1h]) * 3600 > 1
        for: 5s
        labels:
          severity: High
        annotations:
          summary: Pod restarted

验证与更新

修改完配置后,你可以先通过helm lint命令验证values.yaml的语法正确性:

helm lint ./your-prometheus-chart -f values.yaml

确认没有语法错误后,再执行Helm更新命令:

helm upgrade prometheus ./your-prometheus-chart -f values.yaml

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 10:37:49