prometheus+node_exporter+grafana监控K8S信息

prometheus+node_exporter+grafana监控K8S

1.prometheus部署

包下载地址:https://prometheus.io/download/

将包传至/opt

解压
tar xf prometheus-2.53.3.linux-amd64.tar.gz

移动到 /usr/local/prometheus
mv prometheus-2.53.3.linux-amd64 /usr/local/prometheus

prometheus配置文件,可以根据需求更改配置
/usr/local/prometheus/prometheus.yml


配置systemd,用systemctl来管理prometheus

复制代码
cat > /usr/lib/systemd/system/prometheus.service <<'EOF'
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io
After=network.target
   
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/usr/local/prometheus/data/ \
--storage.tsdb.retention=15d \
--web.enable-lifecycle
     
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
   
[Install]
WantedBy=multi-user.target
EOF

启动prometheus

systemctl start prometheus

systemctl enable prometheus

netstat -lntp | grep 9090



Status-Targets 下看到prometheus状态为up

代表能正常采集到数据



2.node_exporter部署

在集群中每个需要监控的K8s节点上部署node_exporter

下载node_exporter包

地址:https://prometheus.io/download/

上传包至/opt

解压包
tar xf node_exporter-1.8.2.linux-amd64.tar.gz

移动到 /usr/local/bin
mv node_exporter-1.8.2.linux-amd64 /usr/local/bin


配置systemd,用systemctl来管理node_exporter

复制代码
cat > /usr/lib/systemd/system/node_exporter.service <<'EOF'
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
 
[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter \
--collector.ntp \
--collector.mountstats \
--collector.systemd \
--collector.tcpstat
 
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
 
[Install]
WantedBy=multi-user.target
EOF

启动node_exporter

systemctl start node_exporter

systemctl enable node_exporter

netstat -lntp | grep :9100


3.修改prometheus配置文件

修改prometheus配置文件,在末尾加入被监控的k8s集群信息

vim /usr/local/prometheus/prometheus.yml

复制代码
  - job_name: nodes
    metrics_path: "/metrics"
    static_configs:
    - targets:
	  - 192.168.xx.x:9100
	  - 192.168.xx.x:9100
	  - 192.168.xx.x:9100
      labels:
        service: kubernetes

重载prometheus服务

systemctl reload prometheus

再次打开prometheus,验证k8s集群数据是否采集到


4.grafana部署

grafana官网:https://grafana.com/grafana/download/11.5.0

安装grafana

sudo yum install -y https://dl.grafana.com/enterprise/release/grafana-enterprise-11.5.0-1.x86_64.rpm


启动grafana

复制代码
systemctl start grafana-server

systemctl enable grafana-server

netstat -lntp | grep 3000

访问http://grafana服务IP:3000/

用户名/密码:admin/admin

进入主界面

配置数据源

添加新的数据源

选择prometheus

配置prometheus地址

在最下方点保存

添加模版

导入模版

在模版网站,选择模版,复制ID

我用的模版地址:

https://grafana.com/grafana/dashboards/16098-node-exporter-dashboard-20240520-job/

导入ID

最后在面板上查看监控的k8s的信息即可


参考文档:

https://blog.csdn.net/G_D0120/article/details/139652201?fromshare=blogdetail\&sharetype=blogdetail\&sharerId=139652201\&sharerefer=PC\&sharesource=Wangjiachenga\&sharefrom=from_link

https://blog.csdn.net/weixin_42171272/article/details/138714827?fromshare=blogdetail\&sharetype=blogdetail\&sharerId=138714827\&sharerefer=PC\&sharesource=Wangjiachenga\&sharefrom=from_link

相关推荐
花酒锄作田10 小时前
Debian 13基于kubeadm和containerd部署单节点kubernetes
kubernetes·containerd·cilium
AC赳赳老秦14 小时前
外文文献精读:DeepSeek翻译并解析顶会论文核心技术要点
前端·flutter·zookeeper·自动化·rabbitmq·prometheus·deepseek
Dontla16 小时前
Kubernetes流量管理双雄:Ingress与Gateway API解析(Nginx与Ingress与Gateway API的关系)
nginx·kubernetes·gateway
七夜zippoe17 小时前
Kubernetes与Python微服务编排实战:从基础部署到自动扩缩容
python·微服务·kubernetes·service·hpa
Hello.Reader17 小时前
Flink CLI 从提交作业到 Savepoint/Checkpoint、再到 YARN/K8S 与 PyFlink
大数据·flink·kubernetes
qq_312920112 天前
Proxmox VE 监控:把集群指标秒级推送到 InfluxDB 2.x,Grafana 大屏一步到位
运维·grafana
刘叨叨趣味运维2 天前
解剖K8s控制平面(上):API Server与etcd如何成为集群的“大脑“与“记忆“?
平面·kubernetes·etcd
-dcr2 天前
56.kubernetes弹性伸缩
云原生·容器·kubernetes
Hui Baby2 天前
K8S联邦负载
java·容器·kubernetes
qq_312920112 天前
K8s Ingress实战:七层负载均衡流量治理
容器·kubernetes·负载均衡