2023-07-31 09:11:11 +08:00
|
|
|
|
[#]: subject: "How to Install and Access Kubernetes Dashboard Step-by-Step"
|
|
|
|
|
[#]: via: "https://www.linuxtechi.com/how-to-install-kubernetes-dashboard/"
|
|
|
|
|
[#]: author: "Pradeep Kumar https://www.linuxtechi.com/author/pradeep/"
|
|
|
|
|
[#]: collector: "lkxed"
|
|
|
|
|
[#]: translator: "geekpi"
|
2023-08-05 13:29:41 +08:00
|
|
|
|
[#]: reviewer: "wxy"
|
|
|
|
|
[#]: publisher: "wxy"
|
|
|
|
|
[#]: url: "https://linux.cn/article-16064-1.html"
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
分步指南:安装和访问 Kubernetes 仪表板
|
2023-07-31 09:11:11 +08:00
|
|
|
|
======
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
![][0]
|
|
|
|
|
|
2023-07-31 09:11:11 +08:00
|
|
|
|
Kubernetes 是一个开源容器编排平台,已成为大规模管理容器化应用的首选解决方案。虽然 Kubernetes 提供了强大的命令行工具来管理集群,但有时可视化界面可以使监控和管理部署变得更加容易。Kubernetes 仪表板是一个基于 Web 的用户界面,可让你可视化 Kubernetes 集群并与之交互。
|
|
|
|
|
|
|
|
|
|
在这篇博文中,我们将逐步引导你完成安装和访问 Kubernetes Dashboard 的过程,使你能够简化 Kubernetes 管理任务。
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
先决条件:
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
在安装 Kubernetes Dashboard 之前,请确保你有一个正在运行的 Kubernetes 集群并具有必要的管理访问权限。
|
|
|
|
|
|
|
|
|
|
### 安装 Kubernetes 仪表板
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
为集群安装 Kubernetes 仪表板的简单方法是通过 Helm Chart。Kubernetes 仪表板现在依赖于 cert-manager 和 nginx-ingress-controller。幸运的是,可以使用 Helm Chart 自动安装这些依赖项。但是,如果你已经安装了这些组件,则可以在安装 Chart 时通过设置标志 `–set=nginx.enabled=false` 和 `–set=cert-manager.enabled=false` 来禁用它们的安装。
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
事不宜迟,让我们进入安装步骤。
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
#### 1)安装 Helm
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
使用终端或命令提示符访问集群的主节点。如果没有安装,请安装 helm。运行以下命令。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
|
|
|
|
|
$ chmod 700 get_helm.sh
|
|
|
|
|
$ ./get_helm.sh
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][1]
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
#### 2)添加 Kubernetes 仪表板 Helm 仓库
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
运行以下 `helm` 命令来添加仪表板仓库:
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
|
|
|
|
|
$ helm repo list
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][2]
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
#### 3)安装 Kubernetes 仪表板
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
要使用 `helm` 安装 Kubernetes 仪表板,请运行以下命令:
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][3]
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
上面的输出确认仪表板已部署在 `Kubernetes-dashboard` 命名空间中。因此,要访问仪表板,请运行:
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-nginx-controller 8443:443
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][4]
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
现在,打开运行上述命令的系统的 Web 浏览器,输入以下 URL:
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
```
|
2023-07-31 09:11:11 +08:00
|
|
|
|
https://localhost:8443
|
2023-08-05 13:29:41 +08:00
|
|
|
|
```
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
![][5]
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
点击“<ruby>接受风险并继续<rt>Accept the Risk and Continue</rt></ruby>”。
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
![][6]
|
|
|
|
|
|
|
|
|
|
正如你在上面看到的,我们需要一个令牌才能登录。因此,让我们在下一步中生成所需的令牌。
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
#### 4)为 Kubernetes 仪表板生成令牌
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
再打开一个到主节点的 SSH 会话,创建一个服务帐户并使用以下 yaml 文件分配所需的权限:
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ vi k8s-dashboard-account.yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: ServiceAccount
|
|
|
|
|
metadata:
|
|
|
|
|
name: admin-user
|
|
|
|
|
namespace: kube-system
|
|
|
|
|
---
|
|
|
|
|
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: kube-system
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
保存并退出文件。
|
|
|
|
|
|
|
|
|
|
接下来通过运行以下命令创建服务帐户:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl create -f k8s-dashboard-account.yaml
|
|
|
|
|
serviceaccount/admin-user created
|
|
|
|
|
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
|
|
|
|
|
$
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
现在,为管理员用户生成令牌,运行:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ kubectl -n kube-system create token admin-user
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![][7]
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
复制此令牌并返回浏览器,将其粘贴到“<ruby>输入令牌<rt>Enter token</rt></ruby>”字段中,如下所示:
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
![][8]
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
点击“<ruby>登录<rt>Login</rt></ruby>”。
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
#### 5) 访问 Kubernetes 仪表板
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
当我们点击上面的“登录”时,我们将看到以下仪表板:
|
|
|
|
|
|
|
|
|
|
![][9]
|
|
|
|
|
|
|
|
|
|
太好了,你现在已登录 Kubernetes 仪表板。以下是一些需要探索的关键特性和功能:
|
|
|
|
|
|
|
|
|
|
- 集群概览:获取集群运行状况、资源利用率和运行 Pod 的概览。
|
|
|
|
|
- 工作负载:查看和管理你的部署、副本集、有状态集和守护程序集。
|
|
|
|
|
- 服务:监控和管理你的服务,包括负载均衡器和外部端点。
|
|
|
|
|
- 配置:探索你的配置映射、密钥和持久卷声明。
|
|
|
|
|
- 存储:管理持久卷和存储类。
|
|
|
|
|
- 命名空间:在命名空间之间切换以查看和管理不同项目或团队的资源。
|
|
|
|
|
|
|
|
|
|
这就是这篇文章的全部内容,我希望你发现它有用且内容丰富。请在下面的评论部分发表你的疑问和反馈。
|
|
|
|
|
|
2023-08-05 13:29:41 +08:00
|
|
|
|
*(题图:MJ/1bd0efb0-d4ee-4c8b-854a-49dbf38c5dd7)*
|
|
|
|
|
|
2023-07-31 09:11:11 +08:00
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: https://www.linuxtechi.com/how-to-install-kubernetes-dashboard/
|
|
|
|
|
|
|
|
|
|
作者:[Pradeep Kumar][a]
|
|
|
|
|
选题:[lkxed][b]
|
|
|
|
|
译者:[geekpi](https://github.com/geekpi)
|
2023-08-05 13:29:41 +08:00
|
|
|
|
校对:[wxy](https://github.com/wxy)
|
2023-07-31 09:11:11 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]: https://www.linuxtechi.com/author/pradeep/
|
|
|
|
|
[b]: https://github.com/lkxed/
|
|
|
|
|
[1]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Install-Helm-on-K8s-master-node.png
|
|
|
|
|
[2]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Helm-Repo-Kubernetes-Dashboard.png
|
|
|
|
|
[3]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Installing-Kubernetes-Dashboard-Using-Helm-Command.png
|
|
|
|
|
[4]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Port-Forwarding-Kubernetes-Dashboard-Kubectl-Command.png
|
|
|
|
|
[5]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Accept-Risk-SSL-Kubernetes-Dashboard.png
|
|
|
|
|
[6]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Token-For-Kubernetes-Dashboard-Login.png
|
|
|
|
|
[7]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Generate-Token-K8s-Dashboard-kubectl-Command.png
|
|
|
|
|
[8]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Click-Signin-After-entering-token-kubernetes-dashboard.png
|
|
|
|
|
[9]: https://www.linuxtechi.com/wp-content/uploads/2023/07/Kubernetes-Dashboard-Overview-Ubuntu.png
|
2023-08-05 13:29:41 +08:00
|
|
|
|
[0]: https://img.linux.net.cn/data/attachment/album/202308/05/132420lppzypd5fzvhz1dy.jpg
|