【问题标题】:Updating a k8s Prometheus operator's configs to add a scrape target更新 k8s Prometheus 操作员的配置以添加抓取目标
【发布时间】:2020-08-20 01:06:34
【问题描述】:

我在我的 k8s 集群上部署了 prometheus 算子。现在,我想为我创建的自定义导出器添加一个抓取目标。我创建了 prometheus.yaml 文件,但找不到如何将其应用于现有的 prometheus 运算符。

【问题讨论】:

    标签: kubernetes prometheus prometheus-operator


    【解决方案1】:

    我不知道您如何以及在何处创建/修改您的 prometheus.yaml 文件,但会向您展示管理它的便捷方式。

    首先,我建议您将 prometheus 配置文件 prometheus.yaml 存储为 configmap。这非常有用,而且您将在 CM 中进行的更改将自动进行,而无需您涉及传播/传播到使用/使用此 CM 的 pod。

    因此,在您使用 CM 中的新抓取进行更改后 - 它会 take some time 传播更改。从 ConfigMap 更新到新的 key 投射到 Pod 的总延迟可以长达 kubelet 同步周期(默认为 1 分钟)+ kubelet 中 ConfigMaps 缓存的 ttl(默认为 1 分钟)。

    现在是时候进行实时更改了.. Prometheus 可以选择在飞行时重新加载其配置。你有两个选择如何做到这一点。更多信息你可以找到打开Reloading Prometheus’ Configuration url。

    我将仅在一个解决方案上停下来: 您可以向 Prometheus Web 服务器发送 HTTP POST:

    curl -X POST http://localhost:9090/-/reload
    

    请注意,从 Prometheus 2.0 开始, --web.enable-lifecycle 命令 必须传递行标志才能使 HTTP 重新加载工作。 如果重新加载成功,Prometheus 将记录它已更新其目标:

    INFO[0248] Loading configuration file prometheus.yml source=main.go:196
    INFO[0248] Stopping target manager... source=targetmanager.go:203
    INFO[0248] Target manager stopped. source=targetmanager.go:216
    INFO[0248] Starting target manager... source=targetmanager.go:114
    

    还有蛋糕上的樱桃给你:)

    有一个很棒的Prometheus, ConfigMaps and Continuous Deployment 解释了如何使用 prometheus 监控 Prometheus(也许它会以某种方式适用于您的另一个问题)。我想向您展示的主要内容是您可以自动执行 POST 请求。

    所以基本上你需要一个小型的 sidecar 容器来检查 CM 更改并在有新更改时发送 POST。这个 sidecar 应该和 prometheus 在同一个 pod 中

    在此处复制文章中的粘贴示例以供将来参考

     spec:
      containers:
      - name: prometheus
        ...
        volumeMounts:
        - name: config-volume
          mountPath: /etc/prometheus
      - name: watch
        image: weaveworks/watch:master-5b2a6e5
        imagePullPolicy: IfNotPresent
        args: ["-v", "-t", "-p=/etc/prometheus", "curl", "-X", "POST", "--fail", "-o", "-", "-sS", "http://localhost:80/-/reload"]
        volumeMounts:
        - name: config-volume
          mountPath: /etc/prometheus
      volumes:
        - name: config-volume
          configMap:
            name: prometheus-config
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      • 2019-04-13
      • 2021-10-31
      • 1970-01-01
      • 2022-01-24
      • 1970-01-01
      • 2021-07-15
      相关资源
      最近更新 更多