惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
V
Visual Studio Blog
GbyAI
GbyAI
美团技术团队
云风的 BLOG
云风的 BLOG
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
G
Google Developers Blog
博客园 - 【当耐特】
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
宝玉的分享
宝玉的分享
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
U
Unit 42
P
Proofpoint News Feed
V
V2EX

lvbibir's Blog

shell | 磁盘空间分析脚本 Linux cat 和 tee 命令写入文件 python | 使用 uv 管理你的 python 环境 Claude Code 完整配置指南 windows | mihomo 内核独立部署指南 linux | 磁盘扩容 wsl | 释放长久运行占用的磁盘空间 mysql | 线程上限问题处理 麒麟 7.6 安装谷歌 OTP 认证模块 suse 12sp5 升级 openssh 及 openssl suse 12sp5 部署 mysql 5.7 《谁的青春不迷茫》 docker | centos7 部署 docker vim | 基础配置和使用 windows | rime 输入法 & 雾凇方案 shell | sshpass 批量传输文件及执行命令 wsl | 原生 linux 方式安装 docker nodejs | fnm + pnpm 开发环境配置 wsl | 安装配置 miniconda 虚拟环境 wsl | 自动更新系统代理 wsl | bashrc 环境变量不正确加载的处理方法 wsl | win10 安装 wsl2 troubleshooting | ssh 成功但是 scp 失败 linux | 常用命令总结 docker 部署 piclist shell | 检测网站存活并自动钉钉告警 Zabbix | 监控端口连通性并自动追踪 TCP 路由 windows | 自定义开机快速启动项 windows | miniconda 配置 python 虚拟环境 Zabbix | 监控主机到指定 ip 的流量大小
prometheus (二) 静态配置
lvbibir · 2023-04-25 · via lvbibir's Blog

0 前言

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

1 简介

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

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

additional-scrape-config 官方示例

2 示例

2.1 node-exporter

添加 k8s 集群外的 node-exporter metrics

在 1.1.1.4 部署 node-exporter

docker run -d --name node-exporter \
-p 9102: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

- job_name: "node-exporter"
  static_configs:
  - targets: 
    - "1.1.1.4:9100"

创建 secret additional-scrape-configs.yaml

kubectl create secret generic additional-scrape-configs -n monitoring --from-file=prometheus-additional.yaml  > additional-scrape-configs.yaml
kubectl apply -f additional-scrape-configs.yaml 

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

kind: Prometheus
spec:
  # 添加如下三行
  additionalScrapeConfigs:
    name: additional-scrape-configs  # secret name
    key: prometheus-additional.yaml  # secret key

更新一下 prometheus

[root@k8s-node1 demo]# kubectl apply -f  ../prometheus-prometheus.yaml

查看结果

image-20230427151927477

3 动态更新

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

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

修改 prometheus-additional.yaml

- job_name: "node-exporter"
  static_configs:
  - targets:
    - "1.1.1.4:9100"
    - "192.168.17.99:59100"

更新 secret

kubectl create secret generic additional-scrape-configs -n monitoring --from-file=prometheus-additional.yaml  > additional-scrape-configs.yaml
kubectl apply -f additional-scrape-configs.yaml 

prometheus 会自动重载配置

image-20230427152718192

4 更新失败排查

如果修改了 secret 不生效一定要注意 secret 部署的 namespace 是不是 monitoring

以上