我的k8s集群上有一个现有的prometheus运算符部署。现在,我想为我创建的自定义导出器添加一个抓取目标。我创建了我的prometheus. yaml文件,但找不到如何将其应用于现有的prometheus运算符。
我不知道您如何以及在哪里创建/修改您的prometheus. yaml
文件,但会向您展示管理它的便捷方法。
首先,我建议您将prometheus配置文件prometheus. yaml
存储为config map。这非常有用,并且您将在CM中进行的更改将自动进行,而无需您将其传播/传播到使用/使用此CM的pod。
因此,在CM中使用新抓取进行更改后-传播更改需要一些时间。从ConfigMap更新到新键投影到pod的总延迟可以与kubelet中ConfigMaps缓存(默认为1分钟)的kubelet同步周期(默认为1分钟)ttl一样长。
现在是时候进行实时更改了… Prometheus可以选择在飞行中重新加载其配置。如何做到这一点,您有2个选项。更多信息,您可以在打开重新加载Prometheus的配置网址时找到。
我只在一个解决方案上停止:您可以向Prometheus Web服务器发送HTTPPOST:
curl -X POST http://localhost:9090/-/reload
请注意,从Prometheus 2.0开始,必须传递--web. enable-生命周期命令行标志才能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和持续部署,解释了如何使用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
操作员文档:https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md
但是你必须使用addtionalScrapeConfigsSecret:
additionalScrapeConfigsSecret:
enabled: true
name: additional-scrape-configs
key: prometheus-additional.yaml
否则你会得到错误无法散集!!映射到[]yaml. MapSlice
这里有一个更好的留档:https://github.com/prometheus-community/helm-charts/blob/8b45bdbdabd9b54766c4beb3c562b766b268a034/charts/kube-prometheus-stack/values.yaml#L2691
据此,您可以在不打包的情况下添加抓取配置到如下秘密中:
additionalScrapeConfigs: |
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]