1.下载yaml文件,具体对应版本参考:
Releases · kubernetes/dashboard · GitHub
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.5/aio/deploy/recommended.yaml
2.执行
kubectl apply -f recommended.yaml
3.查看安装情况
kubectl get pods --all-namespaces -o wide | grep dashboard
4.查看svc
kubectl get svc --all-namespaces
5.删除现有的 dashboard 服务,因为该服务的类型是ClusterIP,不便于我们通过浏览器访问,因此需要改成 NodePort 类型的
kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard
6.创建配置文件dashboard-svc.yaml并上传服务器
kind: Service apiVersion: v1 metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboard spec: type: NodePort ports: - port: 443 targetPort: 8443 selector: k8s-app: kubernetes-dashboard
7.创建该 Service
kubectl apply -f dashboard-svc.yaml
8.再次查看服务
kubectl get svc --all-namespaces
9.创建 kubernetes-dashboard 管理员角色,dashboard-svc-account.yaml
apiVersion: v1 kind: ServiceAccount metadata: name: dashboard-admin namespace: kube-system --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: dashboard-admin subjects: - kind: ServiceAccount name: dashboard-admin namespace: kube-system roleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io
10.执行创建
kubectl apply -f dashboard-svc-account.yaml
11.获取token
kubectl get secret -n kube-system |grep admin|awk '{print $1}'
kubectl describe secret dashboard-admin-token-xxxxx -n kube-system|grep '^token'|awk '{print $2}'
12.浏览器访问,如果是edge浏览器会提示“你的连接不是专用连接”,只需要键盘输入thisisunsafe就可继续访问。
12.修改token过期时间,默认过期时间是15分钟。
- '--token-ttl=832000'
参考:【k8s】安装可视化面板Dashboard_k8s1.26安装dashboard_职业代码敲击演奏家的博客-CSDN博客