环境说明:node
主机名 | 操做系统版本 |
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)集群 git
k8s学习资料详见:基本概念、kubectl命令和资料分享 github
Heapster是Kubernetes原生的集群监控方案,Kubelet自身就包含了一个名为cAdvisor的agent,它会收集整个节点和节点上运行的全部单独容器的资源消耗状况。Heapster以pod的方式运行在某个节点上,它经过普通的KubernetesService暴露服务,使外部能够经过一个稳定的IP地址访问。它从集群中全部的cAdvisor收集数据,而后经过一个单独的地址暴露。web
Heapster 将数据按照 Pod 进行分组,将它们存储到预先配置的 backend 并进行可视化展现。Heapster 当前支持的 backend 有 InfluxDB(经过 Grafana 展现),Google Cloud Monitoring 等。docker
lnfluxDB是一个用于存储应用指标,以及其余监控数据的开源的时序数据库。Grafana是一个拥有着华丽的web控制台的数据分析和可视化套件,一样也是开源的,它容许用户对InfluxDB中存储的数据进行可视化,同时发现应用程序的资源使用行为是如何随时间变化的。数据库
安装文件下载:后端
[root@master ~]# git clone https://github.com/kubernetes-retired/heapster.git复制代码
或者api
[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复制代码
注意:每一个节点都需执行以上命令
[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) |
disablecountermetrics | 禁用接收计数器度量以流入数据库(默认:false) |
concurrency |
并发数(默认:1) |
修改heapster-rbac.yaml,将权限修改成cluster-admi
[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复制代码
[root@master kube-config]# kubectl get all -n kube-system -o wide |grep -e monitor -e heapster 复制代码
登录地址: http://172.27.9.131:30011
url为http://172.27.9.131:30012
模板下载
下载地址:https://grafana.com/api/dashboards/3649/revisions/1/download 、
https://grafana.com/api/dashboards/3646/revisions/1/download
导入
同理导入kubernetes-node-statistics
[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:heapster-influxdb-grafana
- 欢迎关注个人公众号:Linux运维实践,关注云计算、容器、k8s、大数据等,你要的干货都在这里!
- 若是您对个人专题内容感兴趣,也能够关注个人博客:loong576的博客