Fork me on GitHub
Fork me on GitHub

Kubernetes1.6集群上(开启了TLS)安装Dashboard

配置和安装 dashboard

这是接着上一篇《二进制方式部署Kubernetes 1.6.0集群(开启TLS)》写的。
Kubernetes Dashboard is a general purpose, web-based UI for Kubernetes clusters. It allows users to manage applications running in the cluster and troubleshoot them, as well as manage the cluster itself.

配置dashboard

官方文件目录:https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dashboard
我使用的文件:
https://github.com/rootsongjc/follow-me-install-kubernetes-cluster/tree/master/manifests/dashboard 下载3个文件下来,并上传到/opt/kube-dashboard/目录下。

[root@node1 opt]# mkdir kube-dashboard
[root@node1 opt]# cd kube-dashboard/
[root@node1 kube-dashboard]# ls
dashboard-controller.yaml  dashboard-rbac.yaml  dashboard-service.yaml

修改dashboard-controller.yaml文件,将里面的image改为:

index.tenxcloud.com/jimmy/kubernetes-dashboard-amd64:v1.6.0

由于 kube-apiserver 启用了 RBAC 授权,而官方源码目录的 dashboard-controller.yaml 没有定义授权的 ServiceAccount,所以后续访问 kube-apiserver 的 API 时会被拒绝,web中提示:

Forbidden (403)

User "system:serviceaccount:kube-system:default" cannot list jobs.batch in the namespace "default". (get jobs.batch)

因此,增加了一个dashboard-rbac.yaml文件,定义一个名为 dashboard 的 ServiceAccount,然后将它和 Cluster Role view 绑定。

执行所有定义的文件

# pwd
/opt/kube-dashboard
# ls
dashboard-controller.yaml  dashboard-rbac.yaml  dashboard-service.yaml
# kubectl create -f .
deployment "kubernetes-dashboard" created
serviceaccount "dashboard" created
clusterrolebinding "dashboard" created
service "kubernetes-dashboard" created

检查执行结果

1.查看分配的 NodePort

# kubectl get services kubernetes-dashboard -n kube-system
NAME                   CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes-dashboard   10.254.207.77   <nodes>       80:32281/TCP   41s
  • NodePort 32281映射到 dashboard pod 80端口。

2.检查 controller

# kubectl get deployment kubernetes-dashboard  -n kube-system
NAME                   DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
kubernetes-dashboard   1         1         1            1           13m
# kubectl get pods  -n kube-system | grep dashboard
kubernetes-dashboard-2888692679-tv54g   1/1       Running   0          13m

访问dashboard

有以下三种方式:

  • kubernetes-dashboard 服务暴露了 NodePort,可以使用 http://NodeIP:nodePort 地址访问 dashboard;
  • 通过 kube-apiserver 访问 dashboard(https 6443端口和http 8080端口方式);
  • 通过 kubectl proxy 访问 dashboard

使用 http://NodeIP:nodePort 地址访问 dashboard

# kubectl get services kubernetes-dashboard -n kube-system
NAME                   CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes-dashboard   10.254.207.77   <nodes>       80:32281/TCP   41s

然后检查出这个pod是运行在集群中哪个服务器上的,我这里是检查是运行在node1节点上的,所以浏览器输入http://172.16.7.151:32281/

通过 kubectl proxy 访问 dashboard

1.启动代理

[root@node1 kube-dashboard]# kubectl proxy --address='172.16.7.151' --port=8086 --accept-hosts='^*$'         
Starting to serve on 172.16.7.151:8086
  • 需要指定 –accept-hosts 选项,否则浏览器访问 dashboard 页面时提示 “Unauthorized”

2.访问
浏览器访问 URL:http://172.16.7.151:8086/ui 自动跳转到:http://172.16.7.151:8086/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard/#/workload?namespace=default

通过 kube-apiserver 访问dashboard

1.获取集群服务地址列表

[root@node1 ~]# kubectl cluster-info
Kubernetes master is running at https://172.16.7.151:6443
KubeDNS is running at https://172.16.7.151:6443/api/v1/proxy/namespaces/kube-system/services/kube-dns
kubernetes-dashboard is running at https://172.16.7.151:6443/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard

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

2.导入证书
将生成的admin.pem证书转换格式。

[root@node1 ~]# cd /etc/kubernetes/ssl/
[root@node1 ~]# openssl pkcs12 -export -in admin.pem  -out admin.p12 -inkey admin-key.pem

将生成的admin.p12证书导入的你的电脑,导出的时候记住你设置的密码,导入的时候还要用到。
如果你不想使用https的话,可以直接访问insecure port 8080端口:http://172.16.7.151:8080/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard

由于缺少 Heapster 插件,当前 dashboard 不能展示 Pod、Nodes 的 CPU、内存等 metric 图形。