前提條件:安裝好了metrics
- 下載需要的配置文件
git clone https://github.com/ielepro/k8s-prometheus-grafana
- 先部署
node_exporter
prometheus
通過(guò)HTTP
周期性抓取指標(biāo)數(shù)據(jù),監(jiān)控目標(biāo)上用于接受并響應(yīng)的數(shù)據(jù)抓取請(qǐng)求的組件統(tǒng)稱(chēng)為export
铡溪。prometheus
為監(jiān)控類(lèi)UNIX
操作系統(tǒng)提供了一個(gè)專(zhuān)用的node_exporter
程序漂辐,能夠收集多種指標(biāo)數(shù)據(jù),k8s
中運(yùn)行為守護(hù)進(jìn)程監(jiān)聽(tīng)在9100端口棕硫,通過(guò)url
路徑/metrics
提供數(shù)據(jù)髓涯。
~]# cd k8s-prometheus-grafana/
~]# ls
grafana node-exporter.yaml prometheus README.md
~]# kubectl apply -f node-exporter.yaml
- 部署
prometheus
我自己部署過(guò)程中遇到的坑:
因?yàn)橹鳈C(jī)配置比較差,但prometheus.deploy.yml
里面定義的resources
的limits
又比較大哈扮,導(dǎo)致一部署memory
與cpu
就被占滿纬纪,然后kube-scheduler-master
與kube-controller-manager-master
一直重啟,最后非郴猓卡包各,只能關(guān)機(jī)重啟解決,所以建議如果自己的主機(jī)資源不太多靶庙,可以適當(dāng)?shù)母囊幌逻@個(gè)資源限制问畅。
比如我的配置:
---
spec:
spec:
containers:
...
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 100m
memory: 150Mi
...
等node_exporter
啟動(dòng)成功運(yùn)行后,就可以一鍵部署prometheus
了
~]# kubectl apply -f prometheus
~]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
metrics-server-5f78f74857-vq8db 1/1 Running 3 21h
node-exporter-6tzrm 1/1 Running 2 15h
prometheus-79bc5658d4-4gn28 1/1 Running 1 104m