一、前置步骤
1、在k8s-master节点安装nfs-server
详见Ubuntu NFS配置笔记_QuancyZhang的博客-CSDN博客
2、配置k8s-master节点nfs服务
mkdir -p /nfs/prometheus/data
echo "/nfs/prometheus/data 192.169.0.140/24(rw,no_root_squash,sync)" >>/etc/exports
systemctl restart nfs
systemctl restart rpcbind
注意:ip地址置换为自己的nfs地址,并且一定要在另一台机器进行mount试验,否则会报错The PersistentVolume "prometheus-data-pv" is invalid: spec.persistentvolumesource: Forbidden
二、开始安装
安装所需脚本全部都在Prometheus.zip-群集服务文档类资源-CSDN下载
1、在kubernetest集群中创建namespace
kubectl apply -f namespace.yaml
2、安装node-exporter
在kubernetest集群中部署node-exporter,Node-exporter用于采集kubernetes集群中各个节点的物理指标,比如:Memory、CPU等。
kubectl apply -f node-exporter.yaml
3、部署Prometheus
kubectl apply -f prometheus.yaml
4、部署grafana
kubectl apply -f grafana.yaml
5、检查运行状况
root@k8s-master:~# kubectl get pod -n ns-monitor
NAME READY STATUS RESTARTS AGE
grafana-6d6cc9dc-s2hr9 1/1 Running 0 18h
node-exporter-krghv 1/1 Running 0 19h
node-exporter-px77p 1/1 Running 0 19h
node-exporter-q7j4m 1/1 Running 0 19h
node-exporter-sc562 1/1 Running 0 19h
node-exporter-w8j29 1/1 Running 0 19h
node-exporter-xggmw 1/1 Running 0 19h
prometheus-5f7cb6d955-d7h25 1/1 Running 0 18h
5、配置grafana数据源
把prometheus配置成数据源 :http://prometheus-service.ns-monitor:9090
6.导入Dashboard
把 kubernetes的Dashboard的模板导入进来,直接把JSON格式内容复制进来。
效果图: