前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >prometheus (二) 静态配置

prometheus (二) 静态配置

作者头像
Amadeus
发布2023-05-02 16:55:40
7930
发布2023-05-02 16:55:40
举报
文章被收录于专栏:linux技术linux技术

0. 前言#

基于 centos7.9 docker-ce-20.10.18 kubelet-1.22.3-0 kube-prometheus-0.10 prometheus-v2.32.1

1. 简介#

https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/additional-scrape-config.md

使用原生的 prometheus 时, 我们创建 job 直接修改配置文件即可, 然而在 prometheus-operator 中所有的配置都抽象成了 k8s CRD 资源, 手动配置 job 需要:

  • 创建 secret
  • 在 prometheus CRD 资源中配置 additionalScrapeConfigs

2. 示例#

2.1 node-exporter#

添加 k8s 集群外的 node-exporter metrics

在 1.1.1.4 部署 node-exporter

代码语言:javascript
复制
docker run -d --name node-exporter \
-p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro"   \
-v "/:/rootfs:ro"        \
registry.cn-hangzhou.aliyuncs.com/lvbibir/node-exporter:v1.3.1 \
--path.sysfs=/host/sys \
--path.rootfs=/roofs 

# 验证可用性
[root@1-1-1-4 ~]# curl -s 1.1.1.4:9100/metrics | head -5
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.000326036
go_gc_duration_seconds{quantile="0.25"} 0.000326036
go_gc_duration_seconds{quantile="0.5"} 0.000714158

创建 job 配置 prometheus-additional.yaml

代码语言:javascript
复制
- job_name: "node-exporter"
  static_configs:
  - targets: 
    - "1.1.1.4:9100"

创建 secret additional-scrape-configs.yaml

代码语言:javascript
复制
[root@k8s-node1 demo]# kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --dry-run -oyaml > additional-scrape-configs.yaml
[root@k8s-node1 demo]# kubectl apply -f additional-scrape-configs.yaml -n monitoring
secret/additional-scrape-configs created

修改 prometheus 资源 prometheus-prometheus.yaml , 添加 additionalScrapeConfigs

代码语言:javascript
复制
kind: Prometheus
spec:
  # 添加如下三行
  additionalScrapeConfigs:
    name: additional-scrape-configs  # secret name
    key: prometheus-additional.yaml  # secret key

更新一下 prometheus

代码语言:javascript
复制
[root@k8s-node1 demo]# kubectl apply -f  ../prometheus-prometheus.yaml

查看结果

image-20230427151927477
image-20230427151927477

3. 动态更新#

后续所有的自定义配置直接更新现有的 secret 即可

比如在之前的 node-exporter 的 job 中新增一个 target

修改 prometheus-additional.yaml

代码语言:javascript
复制
- job_name: "node-exporter"
  static_configs:
  - targets:
    - "1.1.1.4:9100"
    - "192.168.17.99:59100"

更新 secret

代码语言:javascript
复制
[root@k8s-node1 demo]# kubectl create secret generic additional-scrape-configs --from-file=prometheus-additional.yaml --dry-run -oyaml > additional-scrape-configs.yaml
W0427 15:15:52.834817   88217 helpers.go:555] --dry-run is deprecated and can be replaced with --dry-run=client.
[root@k8s-node1 demo]# kubectl apply -f additional-scrape-configs.yaml -n monitoring
secret/additional-scrape-configs configured

prometheus 会自动重载配置

image-20230427152718192
image-20230427152718192
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-04-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 0. 前言#
  • 1. 简介#
  • 2. 示例#
    • 2.1 node-exporter#
    • 3. 动态更新#
    相关产品与服务
    容器服务
    腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档