1. 简介

Heapster提供了整个集群的资源监控,并支持持久化数据存储到InfluxDB、Google Cloud Monitoring或者其他的存储后端。
Heapster从kubelet提供的API采集节点和容器的资源占用。另外,Heapster的 /metrics API提供了Prometheus格式的数据。
InfluxDB是一个开源分布式时序、事件和指标数据库;而Grafana则是InfluxDB的 dashboard,提供了强大的图表展示功能。它们常被组合使用展示图表化的监控数据,也可以将Zabbix作为数据源,进行zabbix的监控数据展示。
Heapster、InfluxDB和Grafana均以Pod的形式启动和运行,其中Heapster需要与Kubernetes Master进行安全连接。

2. 安装配置Heapster、InfluxDB和Grafana

到Heapster获取安装包:

[root@linux-node1 tmp]# wget https://github.com/kubernetes/heapster/archive/v1.5.3.tar.gz
[root@linux-node1 tmp]# tar -xf v1.5.3.tar.gz && cd heapster-1.5.3/deploy/kube-config/influxdb/
[root@linux-node1 kube-config]# ll influxdb/
total 12
-rw-rw-r-- 1 root root 2290 May  1 05:13 grafana.yaml
-rw-rw-r-- 1 root root 1114 May  1 05:13 heapster.yaml
-rw-rw-r-- 1 root root  974 May  1 05:13 influxdb.yaml
[root@linux-node1 kube-config]# ll rbac/
total 4
-rw-rw-r-- 1 root root 264 May  1 05:13 heapster-rbac.yaml
[root@linux-node1 kube-config]#

# 以上是所需要用到的文件

3. 配置Docker Socks5代理(为下载所需镜像做准备)

由于某国的 &@#¥%&¥&&*R#¥…… 你懂的. 导致一些镜像无法pull 我这边利用自己搭建的梯子来进行代理

[root@linux-node1 kube-config]# grep "gcr.io" influxdb/heapster.yaml
        image: gcr.io/google_containers/heapster-amd64:v1.5.3
[root@linux-node1 kube-config]#

# 修改docker服务文件配置, 在[Service]部分添加你自己的ss服务器地址
[root@linux-node1 kube-config]# vim /usr/lib/systemd/system/docker.service
......
......
[Service]
Environment="ALL_PROXY=socks5://192.168.56.1:1080"
......
......

将其复制到其他所有节点,并重载、重启Docker服务, 直接pull一下验证即可

[root@linux-node1 kube-config]# docker pull gcr.io/google_containers/heapster-amd64:v1.5.3

4. 关键点说明:

[root@linux-node1 kube-config]# more influxdb/heapster.yaml
......
......
     - /heapster
        - --source=kubernetes:https://kubernetes.default
        - --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086
......
......

这里保持默认即可

【注意】:URL中的主机名地址使用的是InfluxDB的Service名字,这需要DNS服务正常工作,如果没有配置DNS服务,则也可以使用Service的ClusterIP地址。
另外,InfluxDB服务的名称没有加上命名空间,是因为Heapster服务与InfluxDB服务属于相同的命名空间kube-system。也可以使用上命名空间的全服务名,例如:http://monitoring-influxdb.kube-system:8086

修改 grafana.yaml文件

[root@linux-node1 kube-config]# vim influxdb/grafana.yaml
......
......
apiVersion: v1
kind: Service
metadata:
  labels:
    # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
    # If you are NOT using this as an addon, you should comment out this line.
    kubernetes.io/cluster-service: 'true'
    kubernetes.io/name: monitoring-grafana
  name: monitoring-grafana
  namespace: kube-system
spec:
  # In a production setup, we recommend accessing Grafana through an external Loadbalancer
  # or through a public IP.
  # type: LoadBalancer
  # You could also use NodePort to expose the service at a randomly-generated port
  type: NodePort # 去掉注释即可
  ports:
  - port: 80
    targetPort: 3000
  selector:
    k8s-app: grafana
......
......
  • 定义端口类型为 NodePort,将Grafana暴露在宿主机Node的端口上,以便后续浏览器访问 grafana 的 admin UI 界面

5. 执行

[root@linux-node1 kube-config]# kubectl create -f influxdb/ && kubectl create -f rbac/
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
clusterrolebinding.rbac.authorization.k8s.io "heapster" created

检查执行结果

1. 检查Deployment
[root@linux-node1 kube-config]# kubectl get deployments -n kube-system -o wide | grep -E 'heapster|monitoring'
heapster               1         1         1            1           11s       heapster               gcr.io/google_containers/heapster-amd64:v1.5.3             k8s-app=heapster,task=monitoring
monitoring-grafana     1         1         1            1           11s       grafana                gcr.io/google_containers/heapster-grafana-amd64:v4.4.3     k8s-app=grafana,task=monitoring
monitoring-influxdb    1         1         1            1           11s       influxdb               gcr.io/google_containers/heapster-influxdb-amd64:v1.3.3    k8s-app=influxdb,task=monitoring
2. 检查POD
[root@linux-node1 kube-config]# kubectl get pods -n kube-system -o wide | grep -E 'heapster|monitoring'
heapster-589b7db6c9-pwrks               1/1       Running   0          32s       10.2.97.77   192.168.56.13
monitoring-grafana-d8c8d486c-l9dhx      1/1       Running   0          33s       10.2.97.76   192.168.56.13
monitoring-influxdb-54bd58b4c9-q489p    1/1       Running   0          33s       10.2.70.76   192.168.56.12
3. 检查Service
[root@linux-node1 kube-config]# kubectl get service -n kube-system -o wide | grep -E 'heapster|monitoring'
heapster               ClusterIP   10.1.102.233   <none>        80/TCP          50s       k8s-app=heapster
monitoring-grafana     NodePort    10.1.18.167    <none>        80:21240/TCP    50s       k8s-app=grafana
monitoring-influxdb    ClusterIP   10.1.244.92    <none>        8086/TCP        50s       k8s-app=influxdb
4. 检查 kubernets dashboard 界面,看是显示各 Nodes、Pods 的 CPU、内存、负载等利用率曲线图
5. Grafana的访问:

上面我们不是修改了官方提供的那个grafana.yaml中的那个NodePort嘛,所以我们访问就是
http://NodeIP:NodePort