二进制安装kubernetes v1.11.2 (第十八章 部署 heapster 插件)

 

继续前一章部署。

部署 heapster 插件

18.1 heapster 插件介绍

heapster 是一个收集者,将每个 Node 上的 cAdvisor 的数据进行汇总,然后导入到第三方工具(如InfluxDB)

heapster 是通过调用 kubelet 的 http API 来获取 cAdvisor 的 metrics 数据的

由于 kubelet 只在 10250 端口接收 https 请求,故需要修改 heapster 的 deployment 配置。同时,需要赋予 kube-system:heapster ServiceAccount 调用 kubelet API 的权限。

18.2 下载 heapster 文件

heapster 下载页面

[root@k8s-m1 root]# wget https://github.com/kubernetes/heapster/archive/v1.5.4.tar.gz
[root@k8s-m1 root]# mkdir heapster && cd heapster && tar zxvf v1.5.4.tar.gz
[root@k8s-m1 heapster]# cd heapster-1.5.4/deploy/kube-config/influxdb

18.3 修改配置文件

[root@k8s-m1 influxdb]# pwd
/opt/root/heapster/heapster-1.5.4/deploy/kube-config/influxdb

# 修改 influxdb.yaml
[root@k8s-m1 influxdb]# cp influxdb.yaml{,.orig}
[root@k8s-m1 influxdb]# diff influxdb.yaml.orig influxdb.yaml
<         image: fishchen/heapster-influxdb-amd64:v1.3.3

# 修改 heapster.yaml
[root@k8s-m1 influxdb]# cp heapster.yaml{,.orig}
[root@k8s-m1 influxdb]# diff heapster.yaml.orig heapster.yaml
23c23,24
<         image: gcr.io/google_containers/heapster-amd64:v1.5.3
---
>         #image: gcr.io/google_containers/heapster-amd64:v1.5.3
>         image: fishchen/heapster-amd64:v1.5.3
27c28,29
<         - --source=kubernetes:https://kubernetes.default
---
>         #- --source=kubernetes:https://kubernetes.default
>         - --source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250&insecure=true


# 修改 grafana.yaml
[root@k8s-m1 influxdb]# cp grafana.yaml{,.orig}
[root@k8s-m1 influxdb]# diff grafana.yaml.orig grafana.yaml
>         image: wanghkkk/heapster-grafana-amd64-v4.4.3:v4.4.3
67a69
>   type: NodePort


  • 由于 kubelet 只在 10250 监听 https 请求, 故添加相关参数

18.4 执行所有定义文件

为了减少 heapster 错误日志,建议启动顺序如下:
deploy/kube-config/rbac/heapster-rbac.yaml
deploy/kube-config/influxdb/grafana.yaml
deploy/kube-config/influxdb/influxdb.yaml
deploy/kube-config/influxdb/heapster.yaml

 

[root@k8s-m1 influxdb]# pwd
/opt/root/heapster/heapster-1.5.4/deploy/kube-config/influxdb
[root@k8s-m1 influxdb]# ls *.yaml
grafana.yaml heapster.yaml influxdb.yaml
[root@k8s-m1 influxdb]# kubectl apply -f .

[root@k8s-m1 influxdb]# cd ../rbac/
[root@k8s-m1 rbac]# cp heapster-rbac.yaml heapster-rbac.yaml.orig
# 修改 heapster-rbac.yaml  (此文件可以不修改,直接执行默认的即可)
[root@k8s-m1 rbac]# diff heapster-rbac.yaml.orig heapster-rbac.yaml
4c4
< name: heapster
---
> name: heapster-kubelet-api
8c8
< name: system:heapster
---
> name: system:kubelet-api-admin

[root@k8s-m1 rbac]# kubectl apply -f heapster-rbac.yaml
clusterrolebinding.rbac.authorization.k8s.io/heapster created

  • 将 serviceAccount kube-system:heapster 与 ClusterRole system:kubelet-api-admin 绑定,授予它调用 kubelet API 的权限

查看日志: journalctl -u kubelet

18.5 检查执行结果

[root@k8s-m1 rbac]# kubectl get pods -n kube-system | grep -E 'heapster|monitoring'
heapster-77fd7449fd-k8bmv               1/1       Running   0          21m
monitoring-grafana-cd886b7-w22j4        1/1       Running   0          21m
monitoring-influxdb-c6fbbcc55-kd4rh     1/1       Running   0          21m

检查 kubernetes dashboard 界面,可以正确显示各 Nodes、Pods 的cpu、内存、负载等统计数据和图表

 

 

18.6 访问 grafana

通过 kube-apiserver 访问:

获取  monitoring-grafana 服务的 URL

[root@k8s-m1 rbac]# kubectl cluster-info
Kubernetes master is running at https://192.168.56.6:8443
Heapster is running at https://192.168.56.6:8443/api/v1/namespaces/kube-system/services/heapster/proxy
CoreDNS is running at https://192.168.56.6:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
kubernetes-dashboard is running at https://192.168.56.6:8443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
monitoring-grafana is running at https://192.168.56.6:8443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
monitoring-influxdb is running at https://192.168.56.6:8443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

 

通过 nodePort 访问:

# 获取 nodePort 8987
[root@k8s-m1 influxdb]# kubectl get svc  -n kube-system|grep monitoring-grafana
monitoring-grafana     NodePort    10.254.15.67     <none>        80:8987/TCP     15m

# 浏览器链接 
http://nodeIP:8987

 

 

页面如下:

 

 

 

Heapster命令参考如下:
官方文档:https://github.com/kubernetes/heapster/tree/master/docs
–source: 指定数据获取源。这里我们指定kube-apiserver即可。
后缀参数:
inClusterConfig:
kubeletPort: 指定kubelet的使用端口,默认10255
kubeletHttps: 是否使用https去连接kubelets(默认:false)
apiVersion: 指定K8S的apiversion
insecure: 是否使用安全证书(默认:false)
auth: 安全认证
useServiceAccount: 是否使用K8S的安全令牌

–sink: 指定后端数据存储。这里指定influxdb数据库。
后缀参数:
user: InfluxDB用户
pw: InfluxDB密码
db: 数据库名
secure: 安全连接到InfluxDB(默认:false)
withfields: 使用InfluxDB fields(默认:false)

 

配置 heapster:https://github.com/kubernetes/heapster/blob/master/docs/source-configuration.md

posted on 2018-11-16 17:24  冰冰爱学习  阅读(450)  评论(0编辑  收藏  举报

导航