虽然heapster已经即将退休,为了纪念一下,这篇文章整理一下heapster+grafana+Influxdb组合对于kubernetes的node与资源进行监控的插件安装与设定方法,本文以脚本的方式进行固化,内容仍然放在github的easypack上。
整体操作
- https://blog.csdn.net/liumiaocn/article/details/88413428
事前准备
使用快速安装和部署的一键脚本,快速搭建kubernetes环境,使用命令为
sh all-k8s-mgnt.sh install all
为了验证结果,同时需要确认dashboard能够正常动作,相关设定可参看:
- https://liumiaocn.blog.csdn.net/article/details/88957901
在heapster安装之前,可以看到kube-system的namespace相关的dashboard的展示页面如下所示:

设定方式
之所以为了纪念一下,实在是到现在的版本为之heapster的设定和使用确实非常容易入手,可轻松实现heapster采集,influxdb存储,grafana显示的组合功能,同时与dashboard进行结合显示,而所有这些,基本都没有太多的设定作业要做,一般只需注意如下即可:
- 相关镜像事前docker load或者pull完毕,或者网络条件能够直接在运行时pull下来
- 事前coredns或者其他的dns插件能够正常动作
- 设定相关的RBAC信息
- 设定heapster如下:
--source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250
从这里可以看出,kubernetes.default的转化是需要dns服务器的,如果dns插件如果不设定的话,至少此处需要改成ip方式才能访问,另外其他还有几处需要设定。如果这里能够正常动作,从侧面也能说明前面创建的coredns是能够正常动作的。
安装设定
以heapster官方的设定文件为基础,将上述几点注意事项反映进去,形成相关的yaml文件,然后使用kubectl create,即可完成heapster的安装与设定,在easypack中可以这样的语句进行安装即可:
sh all-k8s-mgnt.sh install heapster
- 安装日志示例
[root@host131 shell]# sh all-k8s-mgnt.sh install heapster
## Tue Apr 2 19:59:45 CST 2019 ACTION: install Service: heapster begins ...
## please make sure you can get the following imagesimage: gcr.io/google_containers/heapster-amd64:v1.5.3
## please make sure you can get the following imagesimage: gcr.io/google_containers/heapster-grafana-amd64:v4.4.3
## please make sure you can get the following imagesimage: gcr.io/google_containers/heapster-influxdb-amd64:v1.3.3
## the following keyword needs to be replaced## replace __HEAPSTER_GRAFANA_NODE_PORT__
## delete service first
/root/easypack/k8s/shell/etc/plugins/heapster/1.5.4## create service
deployment.extensions/monitoring-grafana created
service/monitoring-grafana created
clusterrolebinding.rbac.authorization.k8s.io/heapster created
clusterrolebinding.rbac.authorization.k8s.io/heapster-kubelet-api created
serviceaccount/heapster created
deployment.extensions/heapster created
service/heapster created
deployment.extensions/monitoring-influxdb created
service/monitoring-influxdb created## begin check heapster, wait for 3s ...NAME READY STATUS RESTARTS AGE
pod/heapster-57996f88b4-gqmnd 1/1 Running 0 3s
pod/monitoring-grafana-b575bb8ff-7ltx8 1/1 Running 0 4s
pod/monitoring-influxdb-6d65f866f5-wvxh4 1/1 Running 0 4s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/heapster ClusterIP 10.254.240.42 <none> 80/TCP 5s
service/monitoring-grafana NodePort 10.254.61.98 <none> 80:33308/TCP 5s
service/monitoring-influxdb ClusterIP 10.254.65.95 <none> 8086/TCP 5s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/heapster 1/1 1 1 5s
deployment.apps/monitoring-grafana 1/1 1 1 5s
deployment.apps/monitoring-influxdb 1/1 1 1 5s
NAME DESIRED CURRENT READY AGE
replicaset.apps/heapster-57996f88b4 1 1 1 5s
replicaset.apps/monitoring-grafana-b575bb8ff 1 1 1 5s
replicaset.apps/monitoring-influxdb-6d65f866f5 1 1 1 5s
## Tue Apr 2 19:59:51 CST 2019 ACTION: install Service: heapster ends ...[root@host131 shell]#
结果确认
再次确认dashboard,可看到如下信息,已经可以看到CPU和内存的使用状况

pod的详细信息中也包含相关信息了

确认启动后信息
[root@host131 shell]# kubectl cluster-info
Kubernetes master is running at https://192.168.163.131:6443
Heapster is running at https://192.168.163.131:6443/api/v1/namespaces/kube-system/services/heapster/proxy
CoreDNS is running at https://192.168.163.131:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
monitoring-grafana is running at https://192.168.163.131:6443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
monitoring-influxdb is running at https://192.168.163.131:6443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxyTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@host131 shell]#
可以看到相关组件都已正常动作,同时可以使用上述信息通过grafana确认更加详细的资源监控信息。
通过grafana确认监控信息
通过33308访问grafana
使用grafana需要三个步骤,登录即可看到,此处设定均已完成,heapster采集的数据存储到influxdb中,而influxdb的数据成为grafana显示的数据源,而这些设定在前面均已完成。

可以选择cluster或者pod的状况,这里确认kube-system的namespace下的coredns的pod相关的资源信息,如下所示。

可以选择不同的pod,确认资源的使用状况

也可以选择不同的namespace,比如这里选择default的namespace进行确认


















