1. 下载heapster的代码
直接现在Github上的最新代码。
git clone https://github.com/kubernetes/heapster.git
目前的最高版本是1.5.4。
在heapster/deploy/kube-config/influxdb目录下有几个yaml文件:
-rw-r--r--. 1 root root 2276 10月 5 07:59 grafana.yaml
-rw-r--r--. 1 root root 1100 10月 5 07:59 heapster.yaml
-rw-r--r--. 1 root root 960 10月 5 07:59 influxdb.yaml
我们再看下用了哪些镜像:
$ grep 'image:' *
grafana.yaml: image: k8s.gcr.io/heapster-grafana-amd64:v5.0.4
heapster.yaml: image: k8s.gcr.io/heapster-amd64:v1.5.4
influxdb.yaml: image: k8s.gcr.io/heapster-influxdb-amd64:v1.5.2
2. 下载镜像
由于国内网络限制,不能直接下载k8s.gcr.io中的镜像,所以我在阿里云(https://cr.console.aliyun.com/cn-hangzhou/instances/images)搜索到了下面的镜像:
registry.cn-hangzhou.aliyuncs.com/mirror_googlecontainers/heapster-grafana-amd64:v5.0.4
registry.cn-hangzhou.aliyuncs.com/mirror_googlecontainers/heapster-amd64:v1.5.4
registry.cn-hangzhou.aliyuncs.com/mirror_googlecontainers/heapster-influxdb-amd64:v1.5.2
3. 修改配置文件
sed -i "s/image: .*/image: registry.cn-hangzhou.aliyuncs.com\/mirror_googlecontainers\/heapster-grafana-amd64:v5.0.4/g" grafana.yaml
sed -i "s/image: .*/image: registry.cn-hangzhou.aliyuncs.com\/mirror_googlecontainers\/heapster-amd64:v1.5.4/g" heapster.yaml
sed -i "s/image: .*/image: registry.cn-hangzhou.aliyuncs.com\/mirror_googlecontainers\/heapster-influxdb-amd64:v1.5.2/g" influxdb.yaml
4. 启动
在准备好镜像和修改完配置文件后就可以一键启动了,这不就是使用kbuernetes的方便之处吗?
4.1 创建角色system:heapster
创建并编辑文件 heapster-clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:heapster
rules:
- apiGroups:
- ""
resources:
- events
- namespaces
- nodes
- pods
- nodes/stats
verbs:
- create
- get
- list
- watch
- apiGroups:
- extensions
resources:
- deployments
verbs:
- get
- list
- watch
4.2 创建heapster角色
$ cd heapster/deploy/kube-config/rbac/
$ kubectl create -f heapster-rbac.yaml
4.3 启动heaspter
$ cd heapster/deploy/
$ sh kube.sh start
heapster pods have been setup
4.4 查看状态
# kubectl get -f deploy/kube-config/influxdb/
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.extensions/monitoring-grafana 1/1 1 1 48s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/monitoring-grafana ClusterIP 10.96.101.24 <none> 80/TCP 48s
NAME SECRETS AGE
serviceaccount/heapster 1 48s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.extensions/heapster 1/1 1 1 48s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/heapster ClusterIP 10.99.159.110 <none> 80/TCP 48s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.extensions/monitoring-influxdb 1/1 1 1 48s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/monitoring-influxdb ClusterIP 10.111.175.52 <none> 8086/TCP 48s
4.5 查看页面
现在再打开Dashboard页面就可以看到CPU和Memory的监控信息了。
5. 参考文档
Kubernetes Dashboard集成Heapster
k8s监控 heapster部署
Kubernetes Heapster
后记
虽然在安装了heapster插件后可以在dashboard中看到CPU和Memory的监控信息,但是这仅仅是近实时的监控,收集的metrics被保存到了InfluxDB中,还可以通过Kibana或者Grafana来展示更详细的信息和历史数据,还是有很多事情可以做的。