1、在github上找到yaml地址
https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yaml
2、下载yaml文件
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.4/aio/deploy/recommended.yaml
修改yaml 文件中的Service ,添加type类型为NodePort ,并添加nodePort端口
3、执行安装
kubectl apply -f recommended.yaml
4、创建 serviceaccount
方法一:
直接执行如下命令
kubectl create serviceaccount dashboard-admin -n kube-system
方法二:
添加如下yaml文件并执行:kubectl apply -f dashboard-sa.yaml
# cat dashboard-sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard-admin
namespace: kubernetes-dashboard
5、创建clusterrolebinding为dashboard sa授权集群权限cluster-admin
方法一:
执行如下命令:
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
方法二:
创建如下yaml文件并执行 kubectl apply -f dashboard-clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: dashboard-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:- kind: ServiceAccount
name: dashboard-admin
namespace: kubernetes-dashboard
执行完成后,根据dashboard所在节点登陆:ip:30001 (端口根据前面自定义的端口填写)
提示:使用火狐浏览器访问
查看dashboard所在node 可以用
kubectl get pods -A -o wide
然后找到dashboard 所在的node节点
使用token 登陆
获取token
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
![](https://img.haomeiwen.com/i8246270/29483adef0de507b.png)
登陆成功
![](https://img.haomeiwen.com/i8246270/b1bde52339167bcd.png)
网友评论