1. 程式人生 > >部署 heapster 插件

部署 heapster 插件

grep -E 數據 -c ive problem 所有 -a min res

說明:本部署文章參照了 https://github.com/opsnull/follow-me-install-kubernetes-cluster ,歡迎給作者star

Heapster是一個收集者,將每個Node上的cAdvisor的數據進行匯總,然後導到第三方工具(如InfluxDB)。

Heapster 是通過調用 kubelet 的 http API 來獲取 cAdvisor 的 metrics 數據的。

由於 kublet 只在 10250 端口接收 https 請求,故需要修改 heapster 的 deployment 配置。同時,需要賦予 kube-system:heapster ServiceAccount 調用 kubelet API 的權限。

註意:如果沒有特殊指明,本文檔的所有操作均在 k8s-master1節點上執行。

下載 heapster 文件

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

修改配置

$ 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;
$ 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 請求,故添加相關參數;

下載鏡像

images=(
    heapster-amd64:v1.5.3
    heapster-grafana-amd64:v4.4.3
    heapster-influxdb-amd64:v1.3.3
)

for imageName in ${images[@]} ; do
    docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
    docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName gcr.io/google_containers/$imageName
done

執行所有定義文件

$ 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}
vim heapster-rbac.yaml
 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 的權限;

如果不修改,默認的 ClusterRole system:heapster 權限不足:

E1128 10:00:05.010716 1 manager.go:101] Error in scraping containers from kubelet:172.27.128.150:10250: failed to get all container stats from Kubelet URL "https://172.27.128.150:10250/stats/container/": request failed - "403 Forbidden", response: "Forbidden (user=system:serviceaccount:kube-system:heapster, verb=create, resource=nodes, subresource=stats)" E1128 10:00:05.018556 1 manager.go:101] Error in scraping containers from kubelet:172.27.128.149:10250: failed to get all container stats from Kubelet URL "https://172.27.128.149:10250/stats/container/": request failed - "403 Forbidden", response: "Forbidden (user=system:serviceaccount:kube-system:heapster, verb=create, resource=nodes, subresource=stats)" E1128 10:00:05.022664 1 manager.go:101] Error in scraping containers from kubelet:172.27.128.148:10250: failed to get all container stats from Kubelet URL "https://172.27.128.148:10250/stats/container/": request failed - "403 Forbidden", response: "Forbidden (user=system:serviceaccount:kube-system:heapster, verb=create, resource=nodes, subresource=stats)" W1128 10:00:25.000467 1 manager.go:152] Failed to get all responses in time (got 0/3)

檢查執行結果

[[email protected] influxdb]# kubectl get pods -n kube-system | grep -E heapster|monitoring
heapster-7b5d8fb59c-997p8               1/1     Running   0          10m
monitoring-grafana-59d85ddc6-ws7j9      1/1     Running   0          10m
monitoring-influxdb-5fffc746fd-m7bbb    1/1     Running   0          10m

檢查 kubernets dashboard 界面,可以正確顯示各 Nodes、Pods 的 CPU、內存、負載等統計數據和圖表:

技術分享圖片

訪問 grafana

通過 kube-apiserver 訪問:

獲取 monitoring-grafana 服務 URL:

[[email protected] influxdb]# kubectl cluster-info
Kubernetes master is running at https://192.168.161.150:8443
Heapster is running at https://192.168.161.150:8443/api/v1/namespaces/kube-system/services/heapster/proxy
CoreDNS is running at https://192.168.161.150:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
kubernetes-dashboard is running at https://192.168.161.150:8443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
monitoring-grafana is running at https://192.168.161.150:8443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
monitoring-influxdb is running at https://192.168.161.150:8443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy

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

---恢復內容結束---

部署 heapster 插件