如何为Prometheus运算符启用其他配置

时间:2019-12-05 18:17:38

标签: configuration prometheus prometheus-operator

根据Prometheus-operator documentation,我们应该能够通过机密文件轻松提供其他配置。有人真的成功了吗?我有几个问题:

  • 这些配置将出现在prometheus pod中的什么地方?
  • 此配置应采用普罗米修斯配置文件的形式,还是仅列出其他刮擦条目
  • 我们可以通过file_sd_configs:提供其他文件(json配置)吗?如果可以,如何将这些文件提供给prometheus清单文件?

不管这些问题是什么,我都很难添加其他配置。我基本上遵循了documentation的确切步骤,这是我的观察结果:

  1. 这是我的新配置
    cat prometheus-additional.yaml
    - job_name: "prometheus-custom"
      static_configs:
      - targets: ["localhost:9090"]
  1. 添加新的秘密文件
    kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml
  1. 使用其他配置创建prometheus.yml文件
    apiVersion: monitoring.coreos.com/v1
    kind: Prometheus
    metadata:
      name: prometheus
    spec:
      replicas: 2
      resources:
        requests:
          memory: 400Mi
      additionalScrapeConfigs:
        name: additional-scrape-configs
        key: prometheus-additional.yaml
  1. 部署prometheus.yaml
    kubectl apply -f prometheus.yaml
  1. 检查日志,没有任何迹象表明我的新配置
kubectl logs prometheus-prometheus-0 -c prometheus
level=info ts=2019-12-05T18:07:30.217852541Z caller=main.go:302 msg="Starting Prometheus" version=" (version=2.7.1, branch=HEAD, revision=62e591f928ddf6b3468308b7ac1de1c63aa7fcf3)"
level=info ts=2019-12-05T18:07:30.217916972Z caller=main.go:303 build_context="(go=go1.11.5, user=root@f9f82868fc43, date=20190131-11:16:59)"
level=info ts=2019-12-05T18:07:30.217971648Z caller=main.go:304 host_details="(Linux 4.19.3-300.fc29.x86_64 #1 SMP Wed Nov 21 15:27:25 UTC 2018 x86_64 prometheus-prometheus-0 (none))"
level=info ts=2019-12-05T18:07:30.217994128Z caller=main.go:305 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2019-12-05T18:07:30.218236509Z caller=main.go:306 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-12-05T18:07:30.219359123Z caller=main.go:620 msg="Starting TSDB ..."
level=info ts=2019-12-05T18:07:30.219487263Z caller=web.go:416 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-12-05T18:07:30.230944675Z caller=main.go:635 msg="TSDB started"
level=info ts=2019-12-05T18:07:30.231037536Z caller=main.go:695 msg="Loading configuration file" filename=/etc/prometheus/config_out/prometheus.env.yaml
level=info ts=2019-12-05T18:07:30.23125837Z caller=main.go:722 msg="Completed loading of configuration file" filename=/etc/prometheus/config_out/prometheus.env.yaml
level=info ts=2019-12-05T18:07:30.231294106Z caller=main.go:589 msg="Server is ready to receive web requests."
level=info ts=2019-12-05T18:07:33.568068248Z caller=main.go:695 msg="Loading configuration file" filename=/etc/prometheus/config_out/prometheus.env.yaml
level=info ts=2019-12-05T18:07:33.568305994Z caller=main.go:722 msg="Completed loading of configuration file" filename=/etc/prometheus/config_out/prometheus.env.yaml

而且,当我登录prometheus pod时,也看不到任何其他配置,并且当我检查prometheus Web控制台时,也看不到我的任何配置。

1 个答案:

答案 0 :(得分:0)

事实证明,普罗米修斯运营商仍然根据此ticket依赖清单文件的serviceMonitorSelector: {}部分。因此,为了添加其他配置,我们需要具有以下清单:

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: prometheus
spec:
  replicas: 2
  resources:
    requests:
      memory: 400Mi
  additionalScrapeConfigs:
    name: prometheus-config
    key: prometheus-config.yaml
  serviceMonitorSelector: {}

其中prometheus-config.yaml将包含普罗米修斯刮擦规则,并通过秘密将其部署到普罗米修斯群集。我还凭经验发现,当前的prometheus-operator在prometheus配置(悲伤)中不支持file_sd_configs,有人需要在prometheus-config.yaml文件中编写完整规则。