目錄
前置條件
一、下載yaml文件
二、部署yaml各個(gè)組件
2.1 node-exporter.yaml
2.2 Prometheus
2.3 grafana
2.4訪問(wèn)測(cè)試
三、grafana初始化
3.1加載數(shù)據(jù)源
3.2導(dǎo)入模板
四、helm方式部署
前置條件
安裝好k8s集群(幾個(gè)節(jié)點(diǎn)都可以,本人為了方便實(shí)驗(yàn)k8s集群只有一個(gè)master節(jié)點(diǎn)),注意prometheus是部署在k8s集群內(nèi)部的,不同于傳統(tǒng)監(jiān)控分為監(jiān)控端和被控端。
部署k8s參考教程:Linux部署單節(jié)點(diǎn)k8s_linux單節(jié)點(diǎn)安裝k8s_luo_guibin的博客-CSDN博客
? ? ? ? ? ? ? ? ? ? ? ? ?? ? ??k8s集群環(huán)境的搭建 · 語(yǔ)雀
11.0.1.12 |
k8s-master / node-exporter+prometheus+grafana |
一、下載yaml文件
鏈接:https://pan.baidu.com/s/1vmT0Xu7SBB36-odiCMy9zA??(鏈接永久有效)
提取碼:9999
解壓
[root@prometheus opt]# yum install -y zip unzip tree
[root@prometheus opt]# unzip k8s-prometheus-grafana-master.zip
[root@k8s-master k8s-prometheus-grafana-master]# pwd
/opt/k8s-prometheus-grafana-master
[root@k8s-master k8s-prometheus-grafana-master]# tree
.
├── grafana
│?? ├── grafana-deploy.yaml
│?? ├── grafana-ing.yaml
│?? └── grafana-svc.yaml
├── node-exporter.yaml
├── prometheus
│?? ├── configmap.yaml
│?? ├── prometheus.deploy.yml
│?? ├── prometheus.svc.yml
│?? └── rbac-setup.yaml
└── README.md
二、部署yaml各個(gè)組件
kubectl命令tab補(bǔ)全
[root@k8s-master ~]# yum install -y bash-completion
[root@k8s-master ~]# source <(kubectl completion bash)
2.1 node-exporter.yaml
[root@k8s-master k8s-prometheus-grafana-master]# kubectl apply -f node-exporter.yaml
daemonset.apps/node-exporter created
service/node-exporter created
#因?yàn)橹挥幸粋€(gè)節(jié)點(diǎn),這里如果有多個(gè)節(jié)點(diǎn),節(jié)點(diǎn)數(shù)=node-exporterPod數(shù)
[root@k8s-master k8s-prometheus-grafana-master]# kubectl get pod -A | grep node-exporter
kube-system node-exporter-kpdxh 0/1 ContainerCreating 0 28s
[root@k8s-master k8s-prometheus-grafana-master]# kubectl get daemonset -A | grep exporter
kube-system node-exporter 1 1 1 1 1 <none> 2m43s
[root@k8s-master k8s-prometheus-grafana-master]# kubectl get service -A | grep exporter
kube-system node-exporter NodePort 10.96.73.86 <none> 9100:31672/TCP 2m59s
2.2 Prometheus
[root@k8s-master prometheus]# pwd
/opt/k8s-prometheus-grafana-master/prometheus
[root@k8s-master prometheus]# ls
configmap.yaml prometheus.deploy.yml prometheus.svc.yml rbac-setup.yaml
按照順序?rbac-setup.yaml?configmap.yaml?prometheus.deploy.yml?prometheus.svc.yml ,yaml、yml文件沒區(qū)別,不用在意。
[root@k8s-master prometheus]# kubectl apply -f rbac-setup.yaml
clusterrole.rbac.authorization.k8s.io/prometheus created
serviceaccount/prometheus created
clusterrolebinding.rbac.authorization.k8s.io/prometheus created
[root@k8s-master prometheus]# kubectl apply -f configmap.yaml
configmap/prometheus-config created
[root@k8s-master prometheus]# kubectl apply -f prometheus.deploy.yml
deployment.apps/prometheus created
[root@k8s-master prometheus]# kubectl apply -f prometheus.svc.yml
service/prometheus created
2.3 grafana
[root@k8s-master grafana]# pwd
/opt/k8s-prometheus-grafana-master/grafana
[root@k8s-master grafana]# ls
grafana-deploy.yaml grafana-ing.yaml grafana-svc.yaml
按照順序安裝?grafana-deploy.yaml?grafana-svc.yaml?grafana-ing.yaml
[root@k8s-master grafana]# kubectl apply -f grafana-deploy.yaml
deployment.apps/grafana-core created
[root@k8s-master grafana]# kubectl apply -f grafana-svc.yaml
service/grafana created
[root@k8s-master grafana]# kubectl apply -f grafana-ing.yaml
ingress.extensions/grafana created
檢查三個(gè)pod(node-exporter可能有多個(gè))
[root@k8s-master grafana]# kubectl get pod -A | grep node-exporter
kube-system node-exporter-kpdxh 1/1 Running 0 13m
[root@k8s-master grafana]# kubectl get pod -A | grep prometheus
kube-system prometheus-7486bf7f4b-xb4t8 1/1 Running 0 6m21s
[root@k8s-master grafana]# kubectl get pod -A | grep grafana
kube-system grafana-core-664b68875b-fhjvt 1/1 Running 0 2m18s
檢查服務(wù)service,三個(gè)svc類型均為NodePort
[root@k8s-master grafana]# kubectl get svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7h17m
kube-system grafana NodePort 10.107.115.11 <none> 3000:31748/TCP 3m41s
kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 7h17m
kube-system node-exporter NodePort 10.96.73.86 <none> 9100:31672/TCP 15m
kube-system prometheus NodePort 10.111.178.83 <none> 9090:30003/TCP 7m57s
2.4訪問(wèn)測(cè)試
curl訪問(wèn)測(cè)試?
[root@k8s-master grafana]# curl 127.0.0.1:31672
<html lang="en">
......
#node-exporter收集到的數(shù)據(jù)
[root@k8s-master grafana]# curl 127.0.0.1:31672/metrics
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
[root@k8s-master grafana]# curl 127.0.0.1:30003
<a href="/graph">Found</a>.
[root@k8s-master grafana]# curl 127.0.0.1:31748
<a href="/login">Found</a>.
?訪問(wèn)11.0.1.12:31672/metrics,node-exporter收集到的數(shù)據(jù)
?訪問(wèn)11.0.1.12:30003/graph
選擇 "status"--"targets"
三、grafana初始化
訪問(wèn)11.0.1.12:31748/login
賬號(hào)密碼都是admin
3.1加載數(shù)據(jù)源
監(jiān)聽地址 10.111.178.83:9090,prometheus的service地址,重啟后grafana數(shù)據(jù)源地址可能會(huì)改變導(dǎo)致grafana連接不上prometheus且,注意檢測(cè)數(shù)據(jù)源地址。在左側(cè)configuration--data source可編輯數(shù)據(jù)源。
[root@k8s-master grafana]# kubectl get svc -A | grep prometheus
kube-system prometheus NodePort 10.111.178.83 <none> 9090:30003/TCP 40m
3.2導(dǎo)入模板
模板編號(hào)315
選擇數(shù)據(jù)源prometheus
?完成監(jiān)控
四、helm方式部署
......(待更新)
參考文檔:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-662642.html
原理:Node Exporter 簡(jiǎn)介_node_exporter_富士康質(zhì)檢員張全蛋的博客-CSDN博客文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-662642.html
到了這里,關(guān)于k8s集群監(jiān)控方案--node-exporter+prometheus+grafana的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!