k8s实践(十一):heapster+influxdb+grafana实现kubernetes集群监
- 2019 年 11 月 11 日
- 笔记
环境说明:
主机名 |
操作系统版本 |
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收集数据,然后通过一个单独的地址暴露。

Heapster 将数据按照 Pod 进行分组,将它们存储到预先配置的 backend 并进行可视化展示。Heapster 当前支持的 backend 有 InfluxDB(通过 Grafana 展示),Google Cloud Monitoring 等。

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.yaml、influxdb.yaml、heapster.yaml和heapster-rbac.yaml

修改grafana.yaml,port类型为NodePort,nodePort为30011,可通过http://NodeIp:30011方式访问

修改influxdb.yaml,port类型为NodePort,nodePort为30012,grafana配置数据源会用到

修改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) |

修改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

三、Grafana配置
1.登录grafana

2.配置DataSource



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
导入



同理导入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