新聞中心
環(huán)境說明:
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于做網(wǎng)站、網(wǎng)站建設(shè)、柘城網(wǎng)絡(luò)推廣、微信小程序開發(fā)、柘城網(wǎng)絡(luò)營(yíng)銷、柘城企業(yè)策劃、柘城品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供柘城建站搭建服務(wù),24小時(shí)服務(wù)熱線:18982081108,官方網(wǎng)址:www.cdcxhl.com
主機(jī)名 | 操作系統(tǒng)版本 | ip | docker version | kubelet version | 配置 | 備注 |
---|---|---|---|---|---|---|
master | Centos 7.6.1810 | 172.27.9.131 | Docker 18.09.6 | V1.14.2 | 2C2G | master主機(jī) |
node01 | Centos 7.6.1810 | 172.27.9.135 | Docker 18.09.6 | V1.14.2 | 2C2G | node節(jié)點(diǎn) |
node02 | Centos 7.6.1810 | 172.27.9.136 | Docker 18.09.6 | V1.14.2 | 2C2G | node節(jié)點(diǎn) |
?
k8s集群部署詳見:Centos7.6部署k8s(v1.14.2)集群
k8s學(xué)習(xí)資料詳見:基本概念、kubectl命令和資料分享
k8s高可用集群部署詳見:Centos7.6部署k8s v1.16.4高可用集群(主備模式)
?
一、簡(jiǎn)介
1.heapster簡(jiǎn)介
Heapster是Kubernetes原生的集群監(jiān)控方案,Kubelet自身就包含了一個(gè)名為cAdvisor的agent,它會(huì)收集整個(gè)節(jié)點(diǎn)和節(jié)點(diǎn)上運(yùn)行的所有單獨(dú)容器的資源消耗情況。Heapster以pod的方式運(yùn)行在某個(gè)節(jié)點(diǎn)上,它通過普通的KubernetesService暴露服務(wù),使外部可以通過一個(gè)穩(wěn)定的IP地址訪問。它從集群中所有的cAdvisor收集數(shù)據(jù),然后通過一個(gè)單獨(dú)的地址暴露。
Heapster 將數(shù)據(jù)按照 Pod 進(jìn)行分組,將它們存儲(chǔ)到預(yù)先配置的 backend 并進(jìn)行可視化展示。Heapster 當(dāng)前支持的 backend 有 InfluxDB(通過 Grafana 展示),Google Cloud Monitoring 等。
2.lnfluxDB和Grafana 簡(jiǎn)介
lnfluxDB是一個(gè)用于存儲(chǔ)應(yīng)用指標(biāo),以及其他監(jiān)控?cái)?shù)據(jù)的開源的時(shí)序數(shù)據(jù)庫。Grafana是一個(gè)擁有著華麗的web控制臺(tái)的數(shù)據(jù)分析和可視化套件,同樣也是開源的,它允許用戶對(duì)InfluxDB中存儲(chǔ)的數(shù)據(jù)進(jìn)行可視化,同時(shí)發(fā)現(xiàn)應(yīng)用程序的資源使用行為是如何隨時(shí)間變化的。
二、heapster安裝
1.安裝文件和鏡像下載
安裝文件下載:
[root@master ~]# git clone https://github.com/kubernetes-retired/heapster.git
或者
[root@master ~]# wget https://github.com/kubernetes-retired/heapster/archive/master.zip
[root@master ~]# unzip master.zip
兩種方式都可以下載安裝文件,本文采取第二種方式
鏡像下載及打標(biāo)簽
[root@node02 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-grafana-amd64:v5.0.4
[root@node02 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2
[root@node02 ~]# docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-amd64:v1.5.4
[root@node02 ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-amd64:v1.5.4 k8s.gcr.io/heapster-amd64:v1.5.4
[root@node02 ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2 k8s.gcr.io/heapster-influxdb-amd64:v1.5.2
[root@node02 ~]# docker image tag registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-grafana-amd64:v5.0.4 k8s.gcr.io/heapster-grafana-amd64:v5.0.4
[root@node02 ~]# docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-amd64:v1.5.4 registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-influxdb-amd64:v1.5.2 registry.cn-hangzhou.aliyuncs.com/google_containers/heapster-grafana-amd64:v5.0.4
注意:每個(gè)節(jié)點(diǎn)都需執(zhí)行以上命令
2.安裝文件修改
[root@master ~]# cd heapster-master/deploy/kube-config/
[root@master kube-config]# pwd
/root/heapster-master/deploy/kube-config
[root@master kube-config]# ll
總用量 0
drwxr-xr-x 2 root root 27 11月 30 2018 google
drwxr-xr-x 2 root root 68 10月 22 15:00 influxdb
drwxr-xr-x 2 root root 32 10月 22 15:02 rbac
drwxr-xr-x 2 root root 38 11月 30 2018 standalone
drwxr-xr-x 2 root root 170 11月 30 2018 standalone-test
drwxr-xr-x 2 root root 145 11月 30 2018 standalone-with-apiserver
[root@master kube-config]# cd influxdb/
[root@master influxdb]# ll
總用量 12
-rw-r--r-- 1 root root 2294 10月 22 14:51 grafana.yaml
-rw-r--r-- 1 root root 1162 10月 22 15:00 heapster.yaml
-rw-r--r-- 1 root root 997 10月 22 14:51 influxdb.yaml
[root@master influxdb]# cd ../rbac/
[root@master rbac]# ll
總用量 4
-rw-r--r-- 1 root root 263 10月 22 15:02 heapster-rbac.yaml
分別修改文件grafana.yaml、influxdb.yaml、heapster.yaml和heapster-rbac.yaml
修改grafana.yaml,port類型為NodePort,nodePort為30011,可通過http://NodeIp:30011方式訪問
修改influxdb.yaml,port類型為NodePort,nodePort為30012,grafana配置數(shù)據(jù)源會(huì)用到
修改heapster.yaml中的source和sink參數(shù)
source: 指定數(shù)據(jù)獲取源
source參數(shù) | 說明 |
---|---|
inClusterConfig | 在與heapster的命名空間關(guān)聯(lián)的服務(wù)帳戶中使用kube config(默認(rèn)值:true) |
kubeletPort | 指定kubelet的使用端口,默認(rèn)10255 |
kubeletHttps | 是否使用https去連接kubelets(默認(rèn):false) |
insecure | 是否使用安全證書(默認(rèn):false) |
auth | 安全認(rèn)證 |
useServiceAccount | 是否使用K8S的安全令牌(默認(rèn):false) |
sink: 指定后端數(shù)據(jù)存儲(chǔ)
sink參數(shù) | 說明 |
---|---|
user | InfluxDB用戶,默認(rèn)root |
pw | InfluxDB密碼,默認(rèn)root |
db | 數(shù)據(jù)庫名,默認(rèn)k8s |
retention | 默認(rèn)infloxDB保留策略的持續(xù)時(shí)間,默認(rèn)值0,表示無限 |
secure | 安全連接到InfluxDB(默認(rèn):false) |
insecuressl | 忽略SSL證書有效性(默認(rèn)值:false) |
withfields | 使用InfluxDB fields(默認(rèn):false) |
cluster_name | 不同cubernete集群的集群名稱(默認(rèn):default) |
disable_counter_metrics | 禁用接收計(jì)數(shù)器度量以流入數(shù)據(jù)庫(默認(rèn):false) |
concurrency | 并發(fā)數(shù)(默認(rèn):1) |
修改heapster-rbac.yaml,將權(quán)限修改為cluster-admi
3.執(zhí)行安裝
[root@master kube-config]# pwd
/root/heapster-master/deploy/kube-config
[root@master kube-config]# kubectl apply -f influxdb/
deployment.extensions/monitoring-grafana created
service/monitoring-grafana created
serviceaccount/heapster created
deployment.extensions/heapster created
service/heapster created
deployment.extensions/monitoring-influxdb created
service/monitoring-influxdb created
[root@master kube-config]# kubectl apply -f rbac/heapster-rbac.yaml
clusterrolebinding.rbac.authorization.k8s.io/heapster created
4.資源查看
[root@master kube-config]# kubectl get all -n kube-system -o wide |grep -e monitor -e heapster
三、Grafana配置
1.登錄grafana
登陸地址: http://172.27.9.131:30011
2.配置DataSource
url為http://172.27.9.131:30012
3.導(dǎo)入模板
模板下載
下載地址:https://grafana.com/api/dashboards/3649/revisions/1/download 、
https://grafana.com/api/dashboards/3646/revisions/1/download
導(dǎo)入
同理導(dǎo)入kubernetes-node-statistics
四、查看Grafana
五、資源刪除
[root@master ~]# kubectl delete -n kube-system ClusterRoleBinding heapster [root@master ~]# kubectl get all -n kube-system -o wide |grep -e monitor -e heapster |awk '{print $1}'|xargs kubectl delete -n kube-system
[root@master ~]# rm -rf heapster-master master.zip
本文所有配置文件已上傳github:https://github.com/loong576/heapster-influxdb-grafana/archive/master.zip
分享名稱:k8s實(shí)踐(十一):heapster+influxdb+grafana實(shí)現(xiàn)kubernetes集群監(jiān)
新聞來源:http://fisionsoft.com.cn/article/ghdhce.html