分步指南：安装和访问 Kubernetes 仪表板
Kubernetes
![](/data/attachment/album/202308/05/132420lppzypd5fzvhz1dy.jpg)


Kubernetes 是一个开源容器编排平台，已成为大规模管理容器化应用的首选解决方案。虽然 Kubernetes 提供了强大的命令行工具来管理集群，但有时可视化界面可以使监控和管理部署变得更加容易。Kubernetes 仪表板是一个基于 Web 的用户界面，可让你可视化 Kubernetes 集群并与之交互。


在这篇博文中，我们将逐步引导你完成安装和访问 Kubernetes Dashboard 的过程，使你能够简化 Kubernetes 管理任务。


先决条件：


在安装 Kubernetes Dashboard 之前，请确保你有一个正在运行的 Kubernetes 集群并具有必要的管理访问权限。


### 安装 Kubernetes 仪表板


为集群安装 Kubernetes 仪表板的简单方法是通过 Helm Chart。Kubernetes 仪表板现在依赖于 cert-manager 和 nginx-ingress-controller。幸运的是，可以使用 Helm Chart 自动安装这些依赖项。但是，如果你已经安装了这些组件，则可以在安装 Chart 时通过设置标志 `–set=nginx.enabled=false` 和 `–set=cert-manager.enabled=false` 来禁用它们的安装。


事不宜迟，让我们进入安装步骤。


#### 1）安装 Helm


使用终端或命令提示符访问集群的主节点。如果没有安装，请安装 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

```

![](/data/attachment/album/202308/05/132634jkxyu30q7e5f4yag.jpg)


#### 2）添加 Kubernetes 仪表板 Helm 仓库


运行以下 `helm` 命令来添加仪表板仓库：



```
$ helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
$ helm repo list

```

![](/data/attachment/album/202308/05/132647y2ujt0weyw2wzyw0.jpg)


#### 3）安装 Kubernetes 仪表板


要使用 `helm` 安装 Kubernetes 仪表板，请运行以下命令：



```
$ helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard

```

![](/data/attachment/album/202308/05/132701x38u3xfh8rr9bf12.jpg)


上面的输出确认仪表板已部署在 `Kubernetes-dashboard` 命名空间中。因此，要访问仪表板，请运行：



```
$ kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-nginx-controller 8443:443

```

![](/data/attachment/album/202308/05/132718jwzb95iippcwlp6h.jpg)


现在，打开运行上述命令的系统的 Web 浏览器，输入以下 URL：



```
https://localhost:8443

```

![](/data/attachment/album/202308/05/132730qjqkxmnzeekkxq7x.jpg)


点击“<ruby> 接受风险并继续 <rt>  Accept the Risk and Continue </rt></ruby>”。


![](/data/attachment/album/202308/05/132744mveh1zb5vhgx50wb.jpg)


正如你在上面看到的，我们需要一个令牌才能登录。因此，让我们在下一步中生成所需的令牌。


#### 4）为 Kubernetes 仪表板生成令牌


再打开一个到主节点的 SSH 会话，创建一个服务帐户并使用以下 yaml 文件分配所需的权限：



```
$ 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

```

![](/data/attachment/album/202308/05/132804eojycd99cdjjzicy.jpg)


复制此令牌并返回浏览器，将其粘贴到“<ruby> 输入令牌 <rt>  Enter token </rt></ruby>”字段中，如下所示：


![](/data/attachment/album/202308/05/132812khmmk9qzm8ffh39c.jpg)


点击“<ruby> 登录 <rt>  Login </rt></ruby>”。


#### 5) 访问 Kubernetes 仪表板


当我们点击上面的“登录”时，我们将看到以下仪表板：


![](/data/attachment/album/202308/05/132838vrp3epbp0hobphpo.jpg)


太好了，你现在已登录 Kubernetes 仪表板。以下是一些需要探索的关键特性和功能：


* 集群概览：获取集群运行状况、资源利用率和运行 Pod 的概览。
* 工作负载：查看和管理你的部署、副本集、有状态集和守护程序集。
* 服务：监控和管理你的服务，包括负载均衡器和外部端点。
* 配置：探索你的配置映射、密钥和持久卷声明。
* 存储：管理持久卷和存储类。
* 命名空间：在命名空间之间切换以查看和管理不同项目或团队的资源。


这就是这篇文章的全部内容，我希望你发现它有用且内容丰富。请在下面的评论部分发表你的疑问和反馈。


*（题图：MJ/1bd0efb0-d4ee-4c8b-854a-49dbf38c5dd7）*




---


via: <https://www.linuxtechi.com/how-to-install-kubernetes-dashboard/>


作者：[Pradeep Kumar](https://www.linuxtechi.com/author/pradeep/) 选题：[lkxed](https://github.com/lkxed/) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
In this blog post, we will show you how to install Kubernetes dashboard using helm step-by-step, empowering you to streamline your Kubernetes management tasks.

Kubernetes, an open-source container orchestration platform, has become the go-to solution for managing containerized applications at scale. While Kubernetes provides powerful command-line tools for managing clusters, sometimes a visual interface can make monitoring and managing your deployments even easier. Kubernetes Dashboard is a web-based user interface that allows you to visualize and interact with your Kubernetes clusters.

#### Prerequisites

Before installing Kubernetes Dashboard, ensure that you have a running [Kubernetes cluster](https://www.linuxtechi.com/install-kubernetes-on-ubuntu-22-04/) and have the necessary administrative access.

## Installing Kubernetes Dashboard

The easy way to install [Kubernetes dashboard](https://github.com/kubernetes/dashboard) for your cluster is via helm chart. Latest Kubernetes dashboard now has a dependency on cert-manager and nginx-ingress-controller. Fortunately, these dependencies can be automatically installed using the Helm chart. However, if you already have these components installed, you can disable their installation by setting the flags —**set=nginx.enabled=false** and **–set=cert-manager.enabled=false** when installing the chart.

Without any further delay, let’s jump into Kubernetes dashboard installation steps,

#### 1) Install Helm

Access your cluster’s master node using a terminal or command prompt. Install helm if not installed. Run the following commands.

$ 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

#### 2) Add Kubernetes Dashboard Helm Repository

Run following helm command to add dashboard repository,

$ helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ $ helm repo list

#### 3) Install Kubernetes Dashboard Using Helm


To install Kubernetes dashboard using helm, run following command,

$ helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard

Output above confirms dashboard has been deployed in Kubernetes-dashboard namespace. So, in order to access dashboard from the cluster locally, run

$ export POD_NAME=$(kubectl get pods -n kubernetes-dashboard -l "app.kubernetes.io/name=kubernetes-dashboard,app.kubernetes.io/instance=kubernetes-dashboard" -o jsonpath="{.items[0].metadata.name}") $ kubectl -n kubernetes-dashboard port-forward $POD_NAME 8443:8443

Now, open the web browser of system on which you have run above command, type following URL

https://localhost:8443

Click on “Accept the Risk and Continue”

As you can see above, we need a token to login. So, let’s generate the required token in the next step.

Accessing Kubernetes Dashboard from Outside

In case you want to access dashboard from outside of Kubernetes cluster then expose the Kubernetes-dashboard deployment using NodePort type, as show below:

$ kubectl expose deployment kubernetes-dashboard --name k8s-svc --type NodePort --port 8443 -n kubernetes-dashboard

Check the dashboard service, run

Next, try to access dashboard from outside of cluster using the URL:

https://<Worker-IP-Address>:31233

#### 4) Generate Token for Kubernetes Dashboard

Open one more ssh session to master node and create a service account and assign required permissions using following yaml file,

$ 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

save and exit the file

Next create service account by running following command

$ kubectl create -f k8s-dashboard-account.yaml serviceaccount/admin-user created clusterrolebinding.rbac.authorization.k8s.io/admin-user created $

Now, generate the token for admin-user, run

$ kubectl -n kube-system create token admin-user

Copy this token and head back to browser, paste it on “Enter Token” field as shown below,

Click on “Sign in”

#### 5) Access Kubernetes Dashboard

When we click on “Sign in” in above then we will get the following dashboard,

Great, you are now logged in to the Kubernetes Dashboard. Here are a few key features and functionalities to explore:

- Cluster Overview: Gain an overview of your cluster’s health, resource utilization, and running pods.
- Workloads: View and manage your deployments, replica sets, stateful sets, and daemon sets.
- Services: Monitor and manage your services, including load balancers and external endpoints.
- Configurations: Explore your config maps, secrets, and persistent volume claims.
- Storage: Manage persistent volumes and storage classes.
- Namespaces: Switch between namespaces to view and manage resources across different projects or teams.

That’s all from this post, I hope you have found it useful and informative. Kindly do post your queries and feedback in below comments section.