当前位置: 首页 > news >正文

helm 部署 Kube-Prometheus + Grafana + 钉钉告警部署 Kube-Prometheus

背景

角色IPK8S 版本容器运行时
k8s-master-1172.16.16.108v1.24.1containerd://1.6.8
k8s-node-1172.16.16.109v1.24.1containerd://1.6.8
k8s-node-2172.16.16.110v1.24.1containerd://1.6.8

安装 kube-prometheus

mkdir -p /data/yaml/kube-prometheus/prometheus && cd /data/yaml/kube-prometheus/prometheus# 添加 bitnami charts 仓库
helm repo add bitnami https://charts.bitnami.com/bitnamihelm search repo kube-prometheushelm pull bitnami/kube-prometheus --version 8.3.0tar -zxvf kube-prometheus-8.3.0.tgzcat > my-values.yaml << EOF
global:storageClass: "nfs-client"  # 默认 storageClassprometheus:service:type: NodePort      # 配置 NodePortnodePorts: http: 30090       # 配置 NodePort 端口persistence:enabled: true       # 开启持久化size: 9Gi           # 存储大小alertmanager:service:type: NodePort      # 配置 NodePortnodePorts: http: 30093       # 配置 NodePort 端口persistence:enabled: true       # 开启持久化size: 9Gi           # 存储大小config:route:receiver: 'devops'   # 告警接收者routes:- match:receiver: 'devops'receivers:- name: 'devops'       # 告警接收者webhook_configs:- url: 'http://prometheus-webhook-dingtalk.kube-prometheus:8060/dingtalk/devops/send'     # 注意这里的 devops 需要与 prometheus-webhook-dingtalk 中的 --ding.profile 值相同send_resolved: true
EOF# 创建命名空间
kubectl create ns kube-prometheus# 测试
helm install --namespace kube-prometheus prometheus -f my-values.yaml --dry-run  kube-prometheus# 启动
helm install --namespace kube-prometheus prometheus -f my-values.yaml  kube-prometheus# 查看
helm -n kube-prometheus lskubectl -n kube-prometheus get pod

访问 Prometheus

http://172.16.16.108:30090/

配置 Pod 告警策略

mkdir -p /data/yaml/kube-prometheus/prometheus/rules && cd /data/yaml/kube-prometheus/prometheus/rulescat >> k8s-pod-rules.yaml << -'EOF'
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:labels:prometheus-name: kube-prometheus-prometheusmanaged-by: prometheus-operator          name: prometheus-k8s-pod-rulesnamespace:  kube-prometheus
spec:groups:- name: PodMemUsagerules:- alert: Pod内存使用率告警expr: sum by (pod, namespace, job, container) (container_memory_working_set_bytes{pod!="",container !=""}) / sum by (pod, namespace, job, container) (container_spec_memory_limit_bytes{pod!="",container !=""}) * 100 != +Inf > 95for: 1mlabels:severity: 紧急告警service: podsannotations:description: "{{$labels.instance}}: 当前Pod内存使用率大于95% ,使用率为: {{ $value }}"summary: "Pod:{{ $labels.pod }} 检测到内存使用率超过limit值95%"  - name: Pod_cpurules:- alert: Pod_CPU使用率告警expr: sum(irate(container_cpu_usage_seconds_total{pod!="",container !=""}[1m])) by (container, pod) / (sum(container_spec_cpu_quota{pod!="",container !=""}/100000) by (container, pod)) * 100 > 130for: 1mlabels:severity: 严重告警service: podsannotations:description: "{{$labels.pod}}: 一分钟内Pod的cpu使用率大于130%,当前的使用率为: {{ $value }}"  - name: Pod_Network_rxrules:- alert: Pod网络IO(rx方向)告警expr: (sum (rate (container_network_receive_bytes_total{pod!=""}[1m])) by (pod)) / 1024  / 1024 > 200for: 1mlabels:severity: 严重告警service: podsannotations:description: "{{$labels.instance}}: 一分钟内Pod的Pod网络IO(rx方向)大于200Mbps,当前的值为: {{ $value }} Mbps"summary: "Pod:{{ $labels.pod }} 检测到一分钟内网络IO(rx方向)过高"  - name: Pod_Network_txrules:- alert: Pod网络IO(tx方向)告警expr: (sum (rate (container_network_transmit_bytes_total{pod!=""}[1m])) by (pod)) / 1024 / 1024 > 200for: 1mlabels:severity: 严重告警service: podsannotations:description: "{{$labels.instance}}: 一分钟内Pod的Pod网络IO(tx方向)大于200Mbps,当前的值为: {{ $value }} Mbps"summary: "检测到一分钟内Pod网络IO(tx方向)过高"  - name: imagepullbackoffrules:- alert: 拉取镜像失败expr: kube_pod_container_status_waiting_reason{reason="ImagePullBackOff"} == 1for: 1mlabels:severity: 紧急告警annotations:summary: "POD:{{ $labels.pod }} 拉取镜像失败,无法创建容器"description: "请确认镜像是否存在"- name: Pod_Start_Exceptionrules:- alert: POD 资源配置不正确expr: sum by (namespace, pod) (kube_pod_status_phase{ phase=~"Pending|Unknown"}) == 1for: 15slabels:severity: 紧急告警annotations:summary: "POD:{{ $labels.pod }} 启动失败,请及时查看"description: "POD 无法正常启动,请查看资源是否配置正确"- name: crashloopbackoffrules:- alert: POD启动失败expr: kube_pod_container_status_waiting_reason{reason="CrashLoopBackOff"} == 1for: 1mlabels:severity: 紧急告警annotations:summary: "POD:{{ $labels.pod }} 启动失败,请查看程序日志"description: "确认配置参数是否正确" 
-EOFkubectl apply -f k8s-pod-rules.yaml# 检查
kubectl -n kube-prometheus get cm

相关文章:

  • Unity照片墙简易圆形交互效果总结
  • 免费软件“蓝莓投屏”:支持多个Airplay同时镜像的投屏软件。
  • Tomcat 启动闪退问题解决方法
  • 考研复试细胞生物学3.细胞骨架(交通网络)
  • Mybatis的动态SQL~
  • 【AIGC调研系列】通义千问、文心一言、抖音云雀、智谱清言、讯飞星火的特点分析
  • ZC706+AD9361 运行 open WiFi
  • Node.js常用命令
  • JavaScript 与 Vue 3:从基础到 MVVM 架构的实践探索
  • 如何开始定制你自己的大型语言模型
  • Springboot整合瀚高
  • 低代码开发:助力企业实现数字化运维体系搭建
  • Golang基础-5
  • 数据结构(六)——图
  • JAVAEE——线程池
  • 【Leetcode】101. 对称二叉树
  • 2019年如何成为全栈工程师?
  • css属性的继承、初识值、计算值、当前值、应用值
  •  D - 粉碎叛乱F - 其他起义
  • HashMap ConcurrentHashMap
  • Javascript 原型链
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • jquery ajax学习笔记
  • miniui datagrid 的客户端分页解决方案 - CS结合
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • VUE es6技巧写法(持续更新中~~~)
  • 人脸识别最新开发经验demo
  • 事件委托的小应用
  • 学习Vue.js的五个小例子
  • 学习使用ExpressJS 4.0中的新Router
  • 从如何停掉 Promise 链说起
  • ​ 全球云科技基础设施:亚马逊云科技的海外服务器网络如何演进
  • ​油烟净化器电源安全,保障健康餐饮生活
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • #大学#套接字
  • (3)Dubbo启动时qos-server can not bind localhost22222错误解决
  • (DenseNet)Densely Connected Convolutional Networks--Gao Huang
  • (LNMP) How To Install Linux, nginx, MySQL, PHP
  • (八十八)VFL语言初步 - 实现布局
  • (二十三)Flask之高频面试点
  • (附源码)springboot家庭装修管理系统 毕业设计 613205
  • (附源码)ssm失物招领系统 毕业设计 182317
  • (接口封装)
  • (十一)c52学习之旅-动态数码管
  • (四)库存超卖案例实战——优化redis分布式锁
  • (原+转)Ubuntu16.04软件中心闪退及wifi消失
  • (原創) 如何讓IE7按第二次Ctrl + Tab時,回到原來的索引標籤? (Web) (IE) (OS) (Windows)...
  • (转)Linux NTP配置详解 (Network Time Protocol)
  • .babyk勒索病毒解析:恶意更新如何威胁您的数据安全
  • .NET CORE 2.0发布后没有 VIEWS视图页面文件
  • .Net Framework 4.x 程序到底运行在哪个 CLR 版本之上
  • .net mvc 获取url中controller和action
  • .net反编译的九款神器
  • .net最好用的JSON类Newtonsoft.Json获取多级数据SelectToken
  • /usr/local/nginx/logs/nginx.pid failed (2: No such file or directory)