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

【架构实战】Kubernetes监控体系:Prometheus + Grafana

一、Kubernetes监控概述

Kubernetes监控是保障集群稳定性的关键:

监控层次:

  • 基础设施层(Node、Pod)
  • 应用层(业务指标)
  • 集群层(K8s组件)

二、Prometheus架构

1. 架构图

┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ Exporter │ │ Exporter │ │ Exporter │ │ (Node) │ │ (Kube) │ │ (App) │ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ │ │ └───────────────────┼───────────────────┘ │ ┌──────┴──────┐ │ Prometheus │ │ Server │ └──────┬──────┘ │ ┌─────────────────┼─────────────────┐ │ │ │ ┌──────┴──────┐ ┌──────┴──────┐ ┌──────┴──────┐ │ Alertmanager│ │ Grafana │ │ Storage │ └─────────────┘ └─────────────┘ └─────────────┘

2. 核心概念

指标类型:

  • Counter:单调递增
  • Gauge:可增可减
  • Histogram:直方图
  • Summary:分位数

三、部署Prometheus

1. Operator部署

# 安装Prometheus Operatorkubectl create namespace monitoring helm repoaddprometheus-community https://prometheus-community.github.io/helm-charts helminstallprometheus prometheus-community/kube-prometheus-stack

2. ServiceMonitor

apiVersion:monitoring.coreos.com/v1kind:ServiceMonitormetadata:name:myapp-monitornamespace:monitoringspec:selector:matchLabels:app:myappendpoints:-port:httppath:/metricsinterval:15s

3. PrometheusRule

apiVersion:monitoring.coreos.com/v1kind:PrometheusRulemetadata:name:myapp-alertsspec:groups:-name:myapprules:-alert:HighMemoryUsageexpr:container_memory_usage_bytes>1e9for:5mlabels:severity:warningannotations:summary:"内存使用率过高"

四、Grafana配置

1. 数据源配置

apiVersion:v1kind:ConfigMapmetadata:name:grafana-datasourcesnamespace:monitoringdata:datasources.yaml:|apiVersion: 1 datasources: - name: Prometheus type: prometheus access: proxy url: http://prometheus-server.monitoring.svc:9090 isDefault: true

2. Dashboard

{"dashboard":{"title":"Kubernetes Cluster","panels":[{"title":"CPU Usage","type":"graph","targets":[{"expr":"rate(container_cpu_usage_seconds_total[5m])"}]}]}}

3. 常用查询

# Node资源使用 node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100 # Pod资源使用 sum(rate(container_cpu_usage_seconds_total{pod!=""}[5m])) by (pod) # K8s组件状态 up{job="kube-apiserver"} # 存储使用 kubelet_volume_stats_used_bytes / kubelet_volume_stats_capacity_bytes

五、告警配置

1. AlertManager配置

apiVersion:monitoring.coreos.com/v1alpha1kind:AlertmanagerConfigmetadata:name:alert-configspec:route:groupBy:['namespace']groupWait:30sgroupInterval:5mrepeatInterval:4hreceiver:'default'receivers:-name:'default'webhookConfigs:-url:'http://notification-service:8080/webhook'

2. 告警规则

groups:-name:k8srules:-alert:PodNotReadyexpr:kube_pod_status_ready{condition="true"}== 0for:5mlabels:severity:criticalannotations:summary:"Pod {{ $labels.namespace }}/{{ $labels.pod }} not ready"-alert:HighMemoryexpr:sum(container_memory_working_set_bytes) by (pod) / 1024/1024>1024for:5mlabels:severity:warning

六、总结

Kubernetes监控最佳实践:

  • Prometheus:指标采集和存储
  • Grafana:可视化展示
  • AlertManager:告警管理
  • ServiceMonitor:自动服务发现

个人观点,仅供参考

http://www.jsqmd.com/news/661371/

相关文章:

  • 2026年围挡厂家推荐:栾城区广霞建材部,工程围挡、彩钢围挡、绿植围挡等全系供应 - 品牌推荐官
  • 不止是变个色:深入Unity Text组件的Color属性,聊聊颜色混合、性能与富文本的实战技巧
  • 已完成流片项目:8bit 40M采样异步SAR ADC(SMIC18mmrf工艺,过DRC/L...
  • 2026年防火门厂家推荐:河北富杰门窗有限公司,304不锈钢防火门、甲级/乙级/丙级防火门全品类供应 - 品牌推荐官
  • 用户看不到最新部署内容,如何强制清除缓存?
  • 如何用Uncle小说桌面阅读器打造你的个人数字图书馆
  • 2026年平板驳船/组装式驳船/平底驳船/开底驳船/甲板驳船厂家推荐:青州市三江机械有限公司,多类型驳船供应 - 品牌推荐官
  • 微信立减金套装回收避坑指南:认准这几点,到账快还省心 - 圆圆收
  • 跨平台QT中文乱码实战:从源码到UI的编码陷阱与系统级解决方案
  • 2026年住人/活动/民宿/网红/高端/多层/工地/定制/移动集装箱房厂家推荐:南阳广聚合钢结构工程有限公司,适配多场景需求 - 品牌推荐官
  • ChampR:英雄联盟玩家的终极助手,告别手动配置的烦恼
  • ESP32-C3开发实战 SPI篇1:驱动OLED屏与温湿度传感器
  • ASOF JOIN 在金融数据分析中为何关键?pandas merge_asof() 如何实现精准时序匹配?
  • Ostrakon-VL-8B多图对比实战案例:连锁门店陈列优化与促销效果评估
  • 2026年X光安检机厂家推荐:沈阳明翰科技有限公司,小型/双视角/单视角/政府/法院/医院/学校/车站安检机全供应 - 品牌推荐官
  • 2026年堆焊公司权威推荐/带极堆焊机,Tig热丝堆焊,法兰堆焊设备,热丝氩弧堆焊设备,多功能堆焊焊接机 - 品牌策略师
  • 2026年双面胶带厂家推荐:深圳市鸿源涵科技有限公司,PVC/EVA/PET/棉纸等双面胶带全品类供应 - 品牌推荐官
  • IQuest-Coder-V1-40B-Instruct实际作品展示:AI写的代码到底有多强
  • PDF转图片踩坑实录:解决PyMuPDF处理中文PDF乱码、图片模糊的实战经验
  • 2026中国聚合物泵站标杆企业白皮书:从技术研发到全周期服务的价值博弈 - 泵站报价15613348888
  • 5步掌握AssetStudio:Unity游戏资源提取终极指南
  • 2026年小型对辊破碎机厂家推荐:立式对辊破碎机/全自动对辊破碎机/移动鄂式破碎机厂家 - 品牌推荐官
  • 火影手游饰品属性洗练全解析:暴击还是攻击?409%攻击加成阈值背后的战力计算逻辑
  • Verilog函数进阶:从基础function到automatic递归函数的完整指南(含阶乘案例)
  • 从Sensor到屏幕:YUV、RGB与RAW DATA格式的选型实战与性能权衡
  • RabbitMQ快速入门
  • 剑指offer | 2.3 数据结构相关题目
  • AI头像生成器多风格覆盖:Qwen3-32B支持23种细分美术风格Prompt生成
  • OBS多路RTMP推流插件:5大核心技术优势深度解析与实战指南
  • 2026年新房装修设计哪个好,这些品牌值得关注的干货指南 - mypinpai