• 对于注定会优秀的人来说,他所需要的,只是时间----博主
  • 手懒得,必受贫穷,手勤的,必得富足----《圣经》
  • 帮助别人,成就自己。愿君在本站能真正有所收获!
  • 如果你在本站中发现任何问题,欢迎留言指正!
  • 本站开启了防爆破关小黑屋机制,如果您是正常登录但被关进小黑屋,请联系站长解除!

<三十五>Kubernetes学习笔记-手动搭建k8s-1.10.4集群插件之heapster

kubernetes eryajf 1个月前 (12-09) 1249℃ 已收录 0个评论
本文预计阅读时间 13 分钟

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

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

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

1,下载 heapster 文件

heapster release 页面 下载最新版本的 heapster

wget https://github.com/kubernetes/heapster/archive/v1.5.3.tar.gz
tar -xzvf v1.5.3.tar.gz
mv v1.5.3.tar.gz heapster-1.5.3.tar.gz

官方文件目录: heapster-1.5.3/deploy/kube-config/influxdb

2,修改配置

$ cd heapster-1.5.3/deploy/kube-config/influxdb

$ cp grafana.yaml{,.orig}

$ diff grafana.yaml.orig grafana.yaml
16c16
<         image: gcr.io/google_containers/heapster-grafana-amd64:v4.4.3
---
>         image: cnych/heapster-grafana-amd64:v4.4.3
67c67
<   # type: NodePort
---
>   type: NodePort
  • 镜像更改成自己已经pull好了的,并且开启 NodePort。
$ cp heapster.yaml{,.orig}

$diff heapster.yaml.orig heapster.yaml
23c23
<         image: gcr.io/google_containers/heapster-amd64:v1.5.3
---
>         image: cnych/heapster-amd64:v1.4.2
27c27
<         - --source=kubernetes:https://kubernetes.default
---
>         - --source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250
  • 由于 kubelet 只在 10250 监听 https 请求,故添加相关参数;
$ cp influxdb.yaml{,.orig}

$ diff influxdb.yaml.orig influxdb.yaml
16c16
<         image: gcr.io/google_containers/heapster-influxdb-amd64:v1.3.3
---
>         image: cnych/heapster-influxdb-amd64:v1.3.3

3,执行所有定义文件

$pwd
/home/k8s/heap/heapster-1.5.3/deploy/kube-config/influxdb

$ ls *.yaml
grafana.yaml  heapster.yaml  influxdb.yaml

$ kubectl create -f  .

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

$ cd ../rbac/

$ pwd
/opt/k8s/heapster-1.5.2/deploy/kube-config/rbac

$ ls
heapster-rbac.yaml

$ cp heapster-rbac.yaml{,.orig}

$ diff heapster-rbac.yaml.orig heapster-rbac.yaml
12a13,26
> ---
> kind: ClusterRoleBinding
> apiVersion: rbac.authorization.k8s.io/v1beta1
> metadata:
>   name: heapster-kubelet-api
> roleRef:
>   apiGroup: rbac.authorization.k8s.io
>   kind: ClusterRole
>   name: system:kubelet-api-admin
> subjects:
> - kind: ServiceAccount
>   name: heapster
>   namespace: kube-system
>


$ kubectl create -f heapster-rbac.yaml
  • 将 serviceAccount kube-system:heapster 与 ClusterRole system:kubelet-api-admin 绑定,授予它调用 kubelet API 的权限;

4,检查执行结果

$kubectl get pods -n kube-system | grep -E 'heapster|monitoring'
heapster-59cbbcb794-j7qx8               1/1       Running   0          5m
monitoring-grafana-555c674887-fjvnw     1/1       Running   0          5m
monitoring-influxdb-7bbf96b889-hjqsg    1/1       Running   0          5m

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

5,访问 grafana

1. 通过 kube-apiserver 访问

获取 monitoring-grafana 服务 URL:

$ kubectl cluster-info

Kubernetes master is running at https://192.168.106.110:8443
CoreDNS is running at https://192.168.106.110:8443/api/v1/namespaces/kube-system/services/coredns:dns/proxy
Heapster is running at https://192.168.106.110:8443/api/v1/namespaces/kube-system/services/heapster/proxy
kubernetes-dashboard is running at https://192.168.106.110:8443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
monitoring-grafana is running at https://192.168.106.110:8443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
monitoring-influxdb is running at https://192.168.106.110:8443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy

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

浏览器访问 URL: https://192.168.106.110:8443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy

2,通过 kubectl proxy 访问:

创建代理

kubectl proxy --address='192.168.106.5' --port=8086 --accept-hosts='^*$'

Starting to serve on 192.168.106.5:8086

浏览器访问 URL:http://192.168.106.5:8086/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy/?orgId=1

3,通过 NodePort 访问:

$ kubectl get svc -n kube-system|grep -E 'monitoring|heapster'
heapster               ClusterIP   10.254.34.87    <none>        80/TCP          12m
monitoring-grafana     NodePort    10.254.186.62   <none>        80:8654/TCP     12m
monitoring-influxdb    ClusterIP   10.254.55.105   <none>        8086/TCP        12m
  • grafana 监听 NodePort 8654;

浏览器访问 URL:http://192.168.106.3:8654/?orgId=1

那么,这个时候,可以通过如下几种方式访问到grafana服务:

进去之后可以点击一下集群,看看里边的一些信息:

6,参考:

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

weinxin
扫码订阅,第一时间获得更新
微信扫码二维码,订阅我们网站的动态,另外不定时发送WordPress小技巧,你可以随时退订,欢迎订阅哦~

二丫讲梵 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明<三十五>Kubernetes学习笔记-手动搭建k8s-1.10.4集群插件之heapster
喜欢 (0)
[如果想支持本站,可支付宝赞助]
分享 (0)
eryajf
关于作者:
学无止境,我愿意无止境学。书山有路,我愿意举身投火,淬炼成金!

您必须 登录 才能发表评论!