Kubernetes 部署手册v1.12.2(20)

  1. 1. 09-3.部署 heapster 插件
    1. 1.1. 下载 heapster 文件
    2. 1.2. 修改配置
    3. 1.3. 执行所有定义文件
    4. 1.4. 检查执行结果
    5. 1.5. 访问 grafana

#Kubernetes部署手册v1.12.2(20)

09-3.部署 heapster 插件

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

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

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

下载 heapster 文件

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

1
2
3
4
cd /opt/k8s/work
wget https://github.com/kubernetes/heapster/archive/v1.5.4.tar.gz
tar -xzvf v1.5.4.tar.gz
mv v1.5.4.tar.gz heapster-1.5.4.tar.gz

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

修改配置

1
2
3
4
5
6
7
$ cd heapster-1.5.4/deploy/kube-config/influxdb
$ cp grafana.yaml{,.orig}
$ diff grafana.yaml.orig grafana.yaml
67c67
< # type: NodePort
---
> type: NodePort
  • 开启 NodePort;
1
2
3
4
5
$ cp heapster.yaml{,.orig}
$ diff heapster.yaml.orig heapster.yaml
< - --source=kubernetes:https://kubernetes.default
---
> - --source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250
  • 由于 kubelet 只在 10250 监听 https 请求,故添加相关参数;

执行所有定义文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$ cd  /opt/k8s/work/heapster-1.5.4/deploy/kube-config/influxdb
$ ls *.yaml
grafana.yaml heapster.yaml influxdb.yaml
$ kubectl create -f .

$ cd ../rbac/
$ 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 的权限;

检查执行结果

1
2
3
4
$ kubectl get pods -n kube-system | grep -E 'heapster|monitoring'
heapster-56c9dc749-j7hvz 1/1 Running 0 1m
monitoring-grafana-c797777db-lnwnc 1/1 Running 0 1m
monitoring-influxdb-cf9d95766-5wd28 1/1 Running 0 1m

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

dashboard-heapster

访问 grafana

  1. 通过 kube-apiserver 访问:

    获取 monitoring-grafana 服务 URL:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    $ kubectl cluster-info
    Kubernetes master is running at https://10.12.11.240:8443
    Heapster is running at https://10.12.11.240:8443/api/v1/namespaces/kube-system/services/heapster/proxy
    CoreDNS is running at https://10.12.11.240:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
    kubernetes-dashboard is running at https://10.12.11.240:8443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
    monitoring-grafana is running at https://10.12.11.240:8443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
    monitoring-influxdb is running at https://10.12.11.240:8443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy

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

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

  1. 通过 NodePort 访问:

    1
    2
    3
    4
    $ kubectl get svc -n kube-system|grep -E 'monitoring|heapster'
    heapster ClusterIP 10.254.199.65 <none> 80/TCP 3m
    monitoring-grafana NodePort 10.254.116.161 <none> 80:31470/TCP 3m
    monitoring-influxdb ClusterIP 10.254.250.185 <none> 8086/TCP 3m
    • grafana 监听 NodePort 31470;

      浏览器访问 URL:http://10.12.11.7:31470/

参考:

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