K8S部署Dashboard和Heapster
0.前言
文章使用的k8s版本為1.10.0,dashboard版本為v1.8.3
系統(tǒng)為CentOS7
總共有三臺機器:
| Name | IP | Role |
|---|---|---|
| ceph1 | 172.16.32.70 | Master |
| ceph2 | 172.16.32.107 | Node |
| ceph3 | 172.16.32.71 | Node |
1.安裝
-
下載官方dashboard的yaml文件
wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.8.3/src/deploy/recommended/kubernetes-dashboard.yaml -
修改鏡像地址
修改yaml文件,將image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3修改為image: registry.cn-hangzhou.aliyuncs.com/zhanye-zhang/kubernetes-dashboard-amd64:v1.8.3
-
暴露端口,以使用NodeIP訪問
在Service部分修改,添加type: NoedPort和nodePort: 300001,修改后Service部分如下:
kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: type: NodePort ports: - port: 443 targetPort: 8443 nodePort: 30001 selector: k8s-app: kubernetes-dashboard -
創(chuàng)建用戶(涉及kubernetes的RBAC Authorization,暫未學(xué)習(xí))
創(chuàng)建一個admin 用戶,并與cluster-admin綁定,新建一個yaml文件用來創(chuàng)建一個admin用戶并賦予管理權(quán)限。
apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: admin-user annotations: rbac.authorization.kubernetes.io/autoupdate: "true" roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kube-system -
執(zhí)行
kubectl create -f .
2.訪問Dashboard
在安裝好Dashboard后(可以使用kubectl get pods -n kube-system |grep dashboard查看是否Running),可以使用https://NodeIp:3000,在這里為:https://172.16.32.70:300001進行訪問。
正常情況下會出現(xiàn)以下頁面:

選擇令牌(也就是token),輸入token。
獲取token的方式:kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin | awk '{print $1}')
成功登入后,會是以下的頁面:

3.安裝heapster
heapster是kubernetes的集群監(jiān)控方案的一種,它通過從節(jié)點上的kubelet獲取監(jiān)控數(shù)據(jù),在dashboard上顯示各個組件的資源消耗情況。
-
下載官方y(tǒng)aml文件
git clone https://github.com/kubernetes/heapster.git四個yaml文件分別在:
heapster/deploy/kube-config/rbac/heapster-rbac.yaml
heapster/deploy/kube-config/influxdb/grafana.yaml
heapster/deploy/kube-config/influxdb/heapster.yaml
heapster/deploy/kube-config/influxdb/influxdb.yaml
-
修改grafana.yaml
在service中添加type: NodePort 和nodePort: 30004
修改鏡像為:registry.cn-hangzhou.aliyuncs.com/zhanye-zhangf/heapster-grafana-amd64:v4.4.3
-
修改heapster.yaml
修改鏡像為:registry.cn-hangzhou.aliyuncs.com/zhanye-zhang/heapster-amd64:v1.5.3
-
修改influxdb.yaml
修改鏡像為:registry.cn-hangzhou.aliyuncs.com/zhanye-zhang/heapster-influxdb-amd64:v1.3.3
執(zhí)行安裝:
kubectl create -f heapster/deploy/kube-config/rbac/heapster-rbac.yaml
kubectl create -f heapster/deploy/kube-config/influxdb/
如果安裝成功,將可以在dashboard上看到以下界面:

也可以通過訪問http://172.16.32.70:30004(這里是http)直接訪問heapster的UI,如下:

也可以通過命令行查看kubectl top pod或kubectl top node