首页 > 解决方案 > helm values.yaml 中的 alerting_rules.yml

问题描述

我已经使用 helm chart 将 prometheus 安装到 AWS EKS Kubernetes 集群中,现在我正在尝试在该图表的 values.yaml 文件中配置我现在正在尝试添加警报。

文件中已经有一个示例,如下所示

## Prometheus server ConfigMap entries
##
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'

当我取消注释此示例并尝试更新 helm 部署时,出现错误 Error: cannot load values.yaml: error converting YAML to JSON: yaml: line 1282: did not find expected node content

它抱怨的线路是groups:线路

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'
  }

我不确定我在这里做错了什么。

我尝试了另一个警报,但它给出了同样的错误

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
  }

标签: prometheuskubernetes-helm

解决方案


似乎删除 {} 解决了它。

例子

serverFiles:


  ## Alerts configuration
  ## Ref: https://prometheus.io/docs/prometheus/latest/configuration/alerting_rules/
  alerting_rules.yml:
    groups:
      - name: pod restarted
        rules:
        - alert: PodRestarted
          expr: kube_pod_container_status_restarts_total < 1
          for: 0s
          labels:
            severity: High
          annotations:
            summary: Pod restarted

推荐阅读