参考文档:html
或者(source code):https://github.com/kubernetes/heapster/releasesnode
开源软件cAdvisor(Container Advisor)用于监控所在节点的容器运行状态,当前已经被默认集成到kubelet组件内,默认使用tcp 4194端口。git
在大规模容器集群,通常使用Heapster+Influxdb+Grafana平台实现集群性能数据的采集,存储与展现。github
组件docker |
版本数据库 |
Remark后端 |
kubernetesapi |
v1.9.2浏览器 |
|
heapster安全 |
v1.5.1 |
|
Influxdb |
v1.3.3 |
|
grafana |
v4.4.3 |
kubernetes部署服务时,为避免部署时发生pull镜像超时的问题,建议提早将相关镜像pull到相关全部节点(如下以kubenode1为例),或搭建本地镜像系统。
# heapster [root@kubenode1 ~]# docker pull netonline/heapster-amd64:v1.5.1 # influxdb [root@kubenode1 ~]# docker pull netonline/heapster-influxdb-amd64:v1.3.3 # grafana [root@kubenode1 ~]# docker pull netonline/heapster-grafana-amd64:v4.4.3
# release下载页:https://github.com/kubernetes/heapster/releases # release中的yaml范本有时较https://github.com/kubernetes/heapster/tree/master/deploy/kube-config/influxdb的yaml新,但区别不大 [root@kubenode1 ~]# cd /usr/local/src/ [root@kubenode1 src]# wget -O heapster-v1.5.1.tar.gz https://github.com/kubernetes/heapster/archive/v1.5.1.tar.gz # yaml范本在heapster/deploy/kube-config/influxdb目录,另有1个heapster-rbac.yaml在heapster/deploy/kube-config/rbac目录,二者目录结构同github [root@kubenode1 src]# tar -zxvf heapster-v1.5.1.tar.gz -C /usr/local/ [root@kubenode1 src]# mv /usr/local/heapster-1.5.1 /usr/local/heapster 本实验使用yaml文件(修改版):https://github.com/Netonline2016/kubernetes/tree/master/addons/heapster
# heapster须要向kubernetes-master请求node列表,须要设置相应权限; # 默认不须要对heapster-rbac.yaml修改,将kubernetes集群自带的ClusterRole :system:heapster作ClusterRoleBinding,完成受权 [root@kubenode1 ~]# cd /usr/local/heapster/deploy/kube-config/rbac/ [root@kubenode1 rbac]# cat heapster-rbac.yaml kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: heapster roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:heapster subjects: - kind: ServiceAccount name: heapster namespace: kube-system
hepster.yaml由3个模块组成:ServiceAccout,Deployment,Service。
默认不须要修改ServiceAccount部分,设置ServiceAccount资源,获取rbac中定义的权限。
# 修改处:第23行,变动镜像名; # --source:配置采集源,使用安全端口调用kubernetes集群api; # --sink:配置后端存储为influxdb;地址采用influxdb的service名,须要集群dns正常工做,若是没有配置dns服务,可以使用service的ClusterIP地址 [root@kubenode1 ~]# cd /usr/local/heapster/deploy/kube-config/influxdb/ [root@kubenode1 influxdb]# sed -i 's|gcr.io/google_containers/heapster-amd64:v1.5.1|netonline/heapster-amd64:v1.5.1|g' heapster.yaml [root@kubenode1 influxdb]# cat heapster.yaml …… apiVersion: extensions/v1beta1 kind: Deployment metadata: name: heapster namespace: kube-system spec: replicas: 1 template: metadata: labels: task: monitoring k8s-app: heapster spec: serviceAccountName: heapster containers: - name: heapster image: netonline/heapster-amd64:v1.5.1 imagePullPolicy: IfNotPresent command: - /heapster - --source=kubernetes:https://kubernetes.default - --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086 ……
默认不须要修改Service部分。
influxdb.yaml由2个模块组成:Deployment,Service。
# 修改处:第16行,变动镜像名; [root@kubenode1 influxdb]# sed -i 's|gcr.io/google_containers/heapster-influxdb-amd64:v1.3.3|netonline/heapster-influxdb-amd64:v1.3.3|g' influxdb.yaml
默认不须要修改Service部分,注意Service名字的对应便可。
grafana.yaml由2个模块组成:Deployment,Service。
# 修改处:第16行,变动镜像名; # 修改处:第43行,取消注释;“GF_SERVER_ROOT_URL”的value值设定后,只能经过API Server proxy访问grafana; # 修改处:第44行,注释本行; # INFLUXDB_HOST的value值设定为influxdb的service名,依赖于集群dns,或者直接使用ClusterIP [root@kubenode1 influxdb]# sed -i 's|gcr.io/google_containers/heapster-grafana-amd64:v4.4.3|netonline/heapster-grafana-amd64:v4.4.3|g' grafana.yaml [root@kubenode1 influxdb]# sed -i '43s|# value:|value:|g' grafana.yaml [root@kubenode1 influxdb]# sed -i '44s|value:|# value:|g' grafana.yaml [root@kubenode1 influxdb]# cat grafana.yaml …… apiVersion: extensions/v1beta1 kind: Deployment metadata: name: monitoring-grafana namespace: kube-system spec: replicas: 1 template: metadata: labels: task: monitoring k8s-app: grafana spec: containers: - name: grafana image: netonline/heapster-grafana-amd64:v4.4.3 ports: - containerPort: 3000 protocol: TCP volumeMounts: - mountPath: /etc/ssl/certs name: ca-certificates readOnly: true - mountPath: /var name: grafana-storage env: - name: INFLUXDB_HOST value: monitoring-influxdb - name: GF_SERVER_HTTP_PORT value: "3000" # The following env variables are required to make Grafana accessible via # the kubernetes api-server proxy. On production clusters, we recommend # removing these env variables, setup auth for grafana, and expose the grafana # service using a LoadBalancer or a public IP. - name: GF_AUTH_BASIC_ENABLED value: "false" - name: GF_AUTH_ANONYMOUS_ENABLED value: "true" - name: GF_AUTH_ANONYMOUS_ORG_ROLE value: Admin - name: GF_SERVER_ROOT_URL # If you're only using the API Server proxy, set this value instead: value: /api/v1/namespaces/kube-system/services/monitoring-grafana/proxy # value: / volumes: - name: ca-certificates hostPath: path: /etc/ssl/certs - name: grafana-storage emptyDir: {} ……
默认不须要修改Service部分,注意Service名字的对应便可。
# 将heapster-rbac.yaml复制到influxdb/目录; [root@kubenode1 ~]# cd /usr/local/heapster/deploy/kube-config/influxdb/ [root@kubenode1 influxdb]# cp /usr/local/heapster/deploy/kube-config/rbac/heapster-rbac.yaml . [root@kubenode1 influxdb]# kubectl create -f .
# 查看deployment与Pod运行状态 [root@kubenode1 ~]# kubectl get deploy -n kube-system | grep -E 'heapster|monitoring' [root@kubenode1 ~]# kubectl get pods -n kube-system | grep -E 'heapster|monitoring'
# 查看service运行状态 [root@kubenode1 ~]# kubectl get svc -n kube-system | grep -E 'heapster|monitoring'
浏览器访问访问dashboard:https://172.30.200.10:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
注意:Dasheboard没有配置hepster监控平台时,不能展现node,Pod资源的CPU与内存等metric图形
Node资源CPU/内存metric图形:
Pod资源CPU/内存metric图形:
# 经过kube-apiserver访问 [root@kubenode1 ~]# kubectl cluster-info
浏览器访问访问dashboard:https://172.30.200.10:6443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
集群节点信息:
Pod信息: