prometheus的相关介绍这里就不做赘述了,不知道的同学可以自行百度,这里重要介绍利用prometheus对k8s的监控,通过grafana进行图形化展示
之前的文档里已经搭建好k8s集群,和k8s的dashboard
k8s集群:https://blog.csdn.net/weixin_50801368/article/details/118050457
dashboard:https://blog.csdn.net/weixin_50801368/article/details/118051156
如果已经搭建好k8s集群也可以参考文档部署自己的监控
node_exporter部署
node_exporter是prometheus最常用的一个组件,负责采集机器(物理机、虚拟机、云主机等)的监控指标数据,能够采集到的指标包括CPU, 内存,磁盘,网络,文件数等信息
需要在集群的每一个节点都安装node_exporter,但是如果我们的集群有上百台,不可能一台一台上去安装组件,和后期的维护,所以我们这里用daemonset控制器来部署node_exporter,保证每一个节点都要一个node_exporter
kubectl create ns monitor-sa #创建一个命名空间
vim /root/k8s/node-export.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-exporter
namespace: monitor-sa
labels:
name: node-exporter
spec:
selector:
matchLabels:
name: node-exporter
template:
metadata:
labels:
name: node-exporter
spec:
hostPID: true
hostIPC: true
hostNetwork: true
containers:
- name: node-exporter
image: prom/node-exporter:v0.16.0
ports:
- containerPort: 9100
resources:
requests:
cpu: 0.15
securityContext:
privileged: true
args:
- --path.procfs
- /host/proc
- --path.sysfs
- /host/sys
- --collector.filesystem.ignored-mount-points
- '"^/(sys|proc|dev|host|etc)($|/)"'
volumeMounts:
- name: dev
mountPath: /host/dev
- name: proc
mountPath: /host/proc
- name: sys
mountPath: /host/sys
- name: rootfs
mountPath: /rootfs
tolerations:
- key: "node-role.kubernetes.io/master"
operator: "Exists"
effect: "NoSchedule"
volumes:
- name: proc
hostPath:
path: /proc
- name: dev
hostPath:
path: /dev
- name: sys
hostPath:
path: /sys
- name: rootfs
hostPath:
path: /
镜像如果没有的话可以私信我要,之后运行文件就可以了,
kubectl apply -f node-export.yaml
[root@master ansible]# kubectl get pods -n monitor-sa -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
node-exporter-lt4sj 1/1 Running 0 7d21h 192.168.1.152 192.168.1.152 <none> <none>
node-exporter-xkk45 1/1 Running 0 7d21h 192.168.1.153 192.168.1.153 <none> <none>
node-exporter-xqhsl 1/1 Running 0 7d21h 192.168.1.151 192.168.1.151 <none> <none>
这个时候就可以通过浏览器访问 http://192.168.1.151:9100/metrics
后面更新 prometheus server的搭建与使用