k8s實踐(十一):heapster+influxdb+grafana實現kubernetes集羣監

環境說明:

主機名 操作系統版本 ip docker version kubelet version 配置 備註
master Centos 7.6.1810 172.27.9.131 Docker 18.09.6 V1.14.2 2C2G master主機
node01 Centos 7.6.1810 172.27.9.135 Docker 18.09.6 V1.14.2 2C2G node節點
node02 Centos 7.6.1810 172.27.9.136 Docker 18.09.6 V1.14.2 2C2G node節點

 

k8s集羣部署詳見:Centos7.6部署k8s(v1.14.2)集羣
k8s學習資料詳見:基本概念、kubectl命令和資料分享

 

一、簡介

1.heapster簡介

Heapster是Kubernetes原生的集羣監控方案,Kubelet自身就包含了一個名爲cAdvisor的agent,它會收集整個節點和節點上運行的所有單獨容器的資源消耗情況。Heapster以pod的方式運行在某個節點上,它通過普通的KubernetesService暴露服務,使外部可以通過一個穩定的IP地址訪問。它從集羣中所有的cAdvisor收集數據,然後通過一個單獨的地址暴露。

圖片.png

Heapster 將數據按照 Pod 進行分組,將它們存儲到預先配置的 backend 並進行可視化展示。Heapster 當前支持的 backend 有 InfluxDB(通過 Grafana 展示),Google Cloud Monitoring 等。

圖片.png

2.lnfluxDB和Grafana 簡介

lnfluxDB是一個用於存儲應用指標,以及其他監控數據的開源的時序數據庫。Grafana是一個擁有着華麗的web控制檯的數據分析和可視化套件,同樣也是開源的,它允許用戶對InfluxDB中存儲的數據進行可視化,同時發現應用程序的資源使用行爲是如何隨時間變化的。

二、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 

兩種方式都可以下載安裝文件,本文采取第二種方式

鏡像下載及打標籤

[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

注意每個節點都需執行以上命令

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.yamlinfluxdb.yamlheapster.yamlheapster-rbac.yaml

圖片.png

修改grafana.yaml,port類型爲NodePort,nodePort爲30011,可通過http://NodeIp:30011方式訪問

圖片.png

修改influxdb.yaml,port類型爲NodePort,nodePort爲30012,grafana配置數據源會用到

圖片.png

修改heapster.yaml中的source和sink參數

source: 指定數據獲取源

source參數 說明
inClusterConfig 在與heapster的命名空間關聯的服務帳戶中使用kube config(默認值:true)
kubeletPort 指定kubelet的使用端口,默認10255
kubeletHttps 是否使用https去連接kubelets(默認:false)
insecure 是否使用安全證書(默認:false)
auth 安全認證
useServiceAccount 是否使用K8S的安全令牌(默認:false)

sink: 指定後端數據存儲

sink參數 說明
user InfluxDB用戶,默認root
pw InfluxDB密碼,默認root
db 數據庫名,默認k8s
retention 默認infloxDB保留策略的持續時間,默認值0,表示無限
secure 安全連接到InfluxDB(默認:false)
insecuressl 忽略SSL證書有效性(默認值:false)
withfields 使用InfluxDB fields(默認:false)
cluster_name 不同cubernete集羣的集羣名稱(默認:default)
disable_counter_metrics 禁用接收計數器度量以流入數據庫(默認:false)
concurrency 併發數(默認:1)

圖片.png

修改heapster-rbac.yaml,將權限修改爲cluster-admi

3.執行安裝

[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    

圖片.png

三、Grafana配置

1.登錄grafana

登陸地址: http://172.27.9.131:30011

圖片.png

2.配置DataSource

圖片.png

圖片.png

圖片.png

url爲http://172.27.9.131:30012

3.導入模板

模板下載

下載地址:https://grafana.com/api/dashboards/3649/revisions/1/download

https://grafana.com/api/dashboards/3646/revisions/1/download

導入

圖片.png

圖片.png

圖片.png

同理導入kubernetes-node-statistics

四、查看Grafana

圖片.png

圖片.png

五、資源刪除

[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 

圖片.png

本文所有配置文件已上傳github:https://github.com/loong576/heapster-influxdb-grafana/archive/master.zip

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章