多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
Dashboard 是基于网页的 Kubernetes 用户界面。 你可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用排错,还能管理集群资源。 **** 参考文档:https://kubernetes.io/zh-cn/docs/tasks/access-application-cluster/web-ui-dashboard/ <br/> >[info]不同版本的 Dashboard 支持的 Kubernetes 版本不同,可以到 https://github.com/kubernetes/dashboard/releases 查看说明。 >[warning]下面的操作都是在**主节点**上执行 **1. 创建 Dashboard** ```shell # kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml ``` <br/> **2. 查看是否已经创建完成** ```shell # kubectl get pods -n kubernetes-dashboard -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES dashboard-metrics-scraper-7bc864c59-bg8zz 1/1 Running 0 3m3s 10.244.1.4 k8s-node1 <none> <none> kubernetes-dashboard-6c7ccbcf87-k6sxk 1/1 Running 0 3m3s 10.244.2.3 k8s-node2 <none> <none> ``` <br/> **3. 设置允许远程访问** ```shell # kubectl -n kubernetes-dashboard edit service kubernetes-dashboard ``` ![](https://img.kancloud.cn/7e/38/7e38ef11ab86439dd2c935b7b8486ffd_1976x678.png) >[info]将`type: ClusterIP`修改成`type: NodePort`即可 <br/> **4. 创建访问账号与角色** ```shell # cat >dashboard-account.yaml<<EOF apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard EOF # kubectl apply -f dashboard-account.yaml ``` >[info]什么都不用改,直接复制粘贴跑命令就行 <br/> **5. 创建 token** ```shell /* --duration=315360000s 为 token 有效时间,如果不指定则默认为 15 分钟过期。*/ /* 315360000s 为 10 年。如果过期可以重新跑该命令生成新的 token */ # kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}" eyJhbGciOiJSUzI1NiIsImtpZ... ``` >[info]保存该 token 到自己的笔记本中,以后登录 dashboard 就一直用该 token 了。 <br/> **6. 查看 dashboard 远程访问端口** ```shell # kubectl -n kubernetes-dashboard get service kubernetes-dashboard NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes-dashboard NodePort 10.101.50.137 <none> 443:31325/TCP 29m ``` >[info]443:31325/TCP 中的 31325 即为远程访问端口。 <br/> **7. 浏览器访问dashboard:https://192.168.1.19:31325/** ``` 192.168.1.19 为主节点的 ipv4 ``` 输入上面创建的 token 进行登录。 ![](https://img.kancloud.cn/ee/53/ee532952f7cbcce4c229ac48f2c12712_1867x577.png) 登录成功后的页面。 ![](https://img.kancloud.cn/7a/08/7a089cb0103b33d97e742334d2e68f9c_2412x873.png)