Install the Dashboard for the Kubernetes (k8s) cluster

Install the dashboard for your Kubernetes cluster

Documentation description

The video tutorial address corresponding to this article:https://www.bilibili.com/video/BV1MF41197RS/?vd_source=98deeeab6739fa30792cfcffa994b50e

In the previous article, we built a kubernetes cluster, article address:

https://blog.csdn.net/m0_51510236/article/details/130842122

In this article, we follow the official documentation to install the Dashboard for this kubernetes cluster. The official documentation address is:

https://v1-26.docs.kubernetes.io/zh-cn/docs/tasks/access-application-cluster/web-ui-dashboard/

Because the kubernetes cluster we built before is version 1.26, as shown in the figure:
Insert image description here

So this time we also installed the dashboard according to the official documentation of version 1.26.

Deploy Dashboard UI

First we need to download the yaml file for deploying the dashboard, download address:https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/ recommended.yaml, then we need to modify one place, that is, starting from line 32, a Service is created:
Insert image description here

But this Service does not specify a type. If no type is specified, it defaults toClusterIP. We all know thatClusterIP cannot be accessed outside the cluster, so We need to modify the type of this Service. If you installed MetalLB like my previous article, then you can directly change the type to LoadBalancer. If you have not installed it, it is recommended that you change the type Changed to NodePort, in order to consider that some friends have not installed MetalLB, then I will directly use the Service of type NodePort and modify the yaml file:

This step is fine without modification, but you will need to use Ingress to expose the service later, which is more troublesome, so it is recommended to modify this step.
Insert image description here

Then copy this file directly to the k8s master node for execution:

kubectl apply -f recommended.yaml

You can view the execution results:
Insert image description here

Next, we use this line of command to monitor whether the dashboard is installed:

watch kubectl get all -o wide -n kubernetes-dashboard

When the status of READY and STATUS is the same as mine, it means that your dashboard has been successfully installed.
Insert image description here

Access the Dashboard user interface

We use the following command to view the ports exposed by kubernetes-dashboard Service:

kubectl get svc -n kubernetes-dashboard -o wide

After executing this command, you can see that the port exposed by this service in my cluster is 30701:
Insert image description here

Next, I can access the dashboard interface through the IP address of any node plus this port (⚠️Note that you must use https to request), the access format:

https://<任意一个节点的IP地址>:30701

Seeing this interface means that your dashboard interface has been successfully accessed. Follow my tips and click to access:
Insert image description here

After that we will come to this interface:
Insert image description here

We need to generate a token to log in to this system. Next, we continue to refer to the official documentation. The document address is:https://github.com/kubernetes/dashboard/blob/master /docs/user/access-control/creating-sample-user.md, you can view the specific content:
Insert image description here

Next we can create a yaml file according to the prompts and execute it. I have extracted the content. Just execute the following command to create this yaml file (name: dashboard-adminuser.yaml) :

cat > dashboard-adminuser.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

View file contents:
Insert image description here

Next we execute this file directly:

kubectl apply -f dashboard-adminuser.yaml

Results of the:
Insert image description here

Next we can directly use the following command to generate the token:

kubectl -n kubernetes-dashboard create token admin-user

You can view the creation results:
Insert image description here

The string output below is the generated token (note to use your own):

eyJhbGciOiJSUzI1NiIsImtpZCI6ImdGX1I2dDlKeDFXMWREVkNId01NZnJVYmxNSTMtb0ZXZjF1RVNJaUVCd2MifQ.eyJhdWQiOlsiaHR0cHM6Ly9rdWJlcm5ldGVzLmRlZmF1bHQuc3ZjLmNsdXN0ZXIubG9jYWwiXSwiZXhwIjoxNjg5MDY0MTIyLCJpYXQiOjE2ODkwNjA1MjIsImlzcyI6Imh0dHBzOi8va3ViZXJuZXRlcy5kZWZhdWx0LnN2Yy5jbHVzdGVyLmxvY2FsIiwia3ViZXJuZXRlcy5pbyI6eyJuYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsInNlcnZpY2VhY2NvdW50Ijp7Im5hbWUiOiJhZG1pbi11c2VyIiwidWlkIjoiYWU4ZjdjMzMtMjg3Zi00ODcyLWJkY2QtZmQ2NzBhNmY1YjBiIn19LCJuYmYiOjE2ODkwNjA1MjIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDphZG1pbi11c2VyIn0.Neeew8FSavlYGU8P32rsPyT77Cx4LlmssueDrPPMRrwsp8jPFt1CO7471EPppzCGZE-IWlqnPHy_ze6eHXj61L6qx2Xm-DDKVR2Bqr3OFdCModrTGcJUnvgsjoa2j82I5B6JBotIgxPVcmESeE0wpNcrNRqbnsaWX5vr2NCzJEABZJI-gjw2cLigKO8lf7yd6uq-1obN9qbslUTnJeog_lPWDzHDU357nVq5RulyZp-oEsBbudWtqyx2h3XD69lV2nJ8sX-0p_Z-xyB2GzKkKRHeI5BhpMrrQomkXNx73um1qNUriQtFiSdrTQ_otR6rnPm6_h4NvL0FwOo_6sys6A

Paste this token directly into the login interface, and then click Login:
Insert image description here

Next we enter the dashboard interface:
Insert image description here

OK, the Kubernetes dashboard is set up!

Guess you like

Origin blog.csdn.net/m0_51510236/article/details/131661606