【问题标题】:Prometheus operator AlertmanagerConfig unknown field "webhook_configs"Prometheus 操作员 AlertmanagerConfig 未知字段“webhook_configs”
【发布时间】:2021-05-30 18:52:42
【问题描述】:

应用这些清单后https://github.com/prometheus-operator/kube-prometheus/blob/main/kustomization.yaml 我想创建AlertManager webhook:

apiVersion: monitoring.coreos.com/v1alpha1
kind: AlertmanagerConfig
metadata:
  name: custom
spec:
  route:
    receiver: custom
    groupBy: ['job']
    groupWait: 30s
    groupInterval: 5m
    repeatInterval: 12h
  receivers:
    - name: custom
      webhook_configs:
        - send_resolved: true
          url: https://example.com

出现错误:

error: error validating "alertmanagerconfig.yaml": error validating data: ValidationError(AlertmanagerConfig.spec.receivers[0]): unknown field "webhook_configs" in com.coreos.monitoring.v1alpha1.AlertmanagerConfig.spec.receivers; if you choose to ignore these errors, turn validation off with --validate=false

如何解决?

【问题讨论】:

    标签: kubernetes prometheus-alertmanager prometheus-operator


    【解决方案1】:

    以此link为参考,

    apiVersion: monitoring.coreos.com/v1alpha1
    kind: AlertmanagerConfig
    metadata:
      name: custom
    spec:
      receivers:
        - name: custom
          webhookConfigs:
            - send_resolved: true
              url: https://example.com
    

    您也可以使用kubectl explain 命令检查字段

    kubectl explain alertmanagerconfig.spec.receivers

    【讨论】:

      【解决方案2】:

      问题在于您使用的是实际 AlertManager 应用程序的配置参考,而不是 Prometheus Operator 提供的 Kubernetes 自定义资源的配置参考。

      Prometheus Operator 采用像 AlertManagerConfig 这样的自定义资源形式提供的配置,并将它们转换为实际的 AlertManager 配置,并更新应用程序使用的配置文件。这是您首先使用运算符的部分原因。它使这些事情对您来说很方便。

      所以你应该在这里使用的实际配置参考是this。 Prometheus Operator 的 github 自述文件中的 part 列出了您可以使用的可用自定义资源。

      【讨论】:

        【解决方案3】:

        除了 Kiran 的回答(谢谢!)之外,还有一点更正 - 实际上是 sendResolved 而不是 send_resolved。

        apiVersion: monitoring.coreos.com/v1alpha1
        kind: AlertmanagerConfig
        metadata:
          name: custom
        spec:
          receivers:
            - name: custom
              webhookConfigs:
                - sendResolved: true
                  url: https://example.com
        

        【讨论】:

          【解决方案4】:

          我通过使用这个 yaml 生成名为 alertmanager-main 的 Kubernetes secret 解决了这个问题:

          global:
            #skipped
          route:
            group_by: ['job']
            receiver: Default
            routes:
              - receiver: Watchdog
                repeat_interval: 1m
                match:
                  alertname: Watchdog  
          
          receivers:
            - name: Watchdog
              webhook_configs:
                - url: https://my.watchdog.webhook.url
          
            # Other things
          

          这是警报管理器配置。

          我会在一段时间后回答我的问题,现在可能已经修复了 Prometheus Operator CRD 的这个问题。

          【讨论】:

            猜你喜欢
            • 2021-05-07
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-05-21
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多