之前在kubernetes中完成的所有操作都是通过命令行工具kubectl完成的。其实,为了提供更丰富的用户体验,kubernetes还开发了一个基于web的用户界面(Dashboard)。用户可以使用Dashboard部署容器化的应用,还可以监控应用的状态,执行故障排查以及管理kubernetes中各种资源。

一 下载yaml,并运行Dashboard

# 下载yaml
# 若链接不可用,可以看我另一篇文章https://blog.csdn.net/wangjie72270/article/details/122341140
[root@k8s-master01 ~]# wget 
https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.ya
ml
# 修改kubernetes-dashboard的Service类型
kind: Service
apiVersion: v1
metadata:
 labels:
 k8s-app: kubernetes-dashboard
 name: kubernetes-dashboard
 namespace: kubernetes-dashboard
spec:
 type: NodePort # 新增
 ports:
 - port: 443
   targetPort: 8443
   nodePort: 30009 # 新增
 selector:
 k8s-app: kubernetes-dashboard
# 部署
[root@k8s-master01 ~]# kubectl create -f recommended.yaml
# 查看namespace下的kubernetes-dashboard下的资源
[root@k8s-master01 ~]# kubectl get pod,svc -n kubernetes-dashboard
NAME                                             READY    STATUS     RESTARTS AGE
pod/dashboard-metrics-scraper-c79c65bb7-zwfvw     1/1     Running     0       111s
pod/kubernetes-dashboard-56484d4c5-z95z5          1/1     Running     0       111s
NAME                                  TYPE         CLUSTER-IP       EXTERNAL-IP     PORT(S)             AGE
service/dashboard-metrics-scraper     ClusterIP    10.96.89.218     <none>         8000/TCP            111s
service/kubernetes-dashboard          NodePort     10.104.178.171   <none>     443:30009/TCP       111s

二 创建访问账户,获取token

# 创建账号
[root@k8s-master01-1 ~]# kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard
# 授权
[root@k8s-master01-1 ~]# kubectl create clusterrolebinding dashboard-admin-rb --
clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin
# 获取账号token
[root@k8s-master01 ~]# kubectl get secrets -n kubernetes-dashboard | grep dashboard-admin
dashboard-admin-token-xbqhh kubernetes.io/service-account-token 3 2m35s
[root@k8s-master01 ~]# kubectl describe secrets dashboard-admin-token-xbqhh -n
kubernetes-dashboard
Name: dashboard-admin-token-xbqhh
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name: dashboard-admin
 kubernetes.io/service-account.uid: 95d84d80-be7a-4d10-a2e0-68f90222d039

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1025 bytes
namespace:  11 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6ImJqUE1HN2xLZVBDYkxfY1ZUZkEydkdNQlFYaEI0dzF4MzFuM1lzZkZLdDQifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtc2VydmljZWFjY291bnQtdG9rZW4tenFnbDgiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLXNlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNWNmOWNjZmEtYmRiNy00MjA0LTk2NDEtODgxMjkxYzM2OGJmIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1zZXJ2aWNlYWNjb3VudCJ9.mRoOk74SyWvvOgBdy_Bd-nLE5bWnM2ZlGULwRQrS_uIi60IBdv8ey65aTL2sa65gB-OlOus1ZfWHNohcqgdC3MhXc9LFiGI27VDbHae0oRGXkqzDgxWXldx8Omsx0B4SRYyRxFUkIRHAUHXHAnXadHXqS8-0x1eY1fGpyP0RN5DTkstgMQxwgwWmrkmDrgTfuHrujZKfndkmtPjQMPvMpi88ysBCpiNJv210oi-wOOHkyOUV7iD0EH0gJYsSOFVHgeZF94zKVvFkEVhDXOcX1XJmn7vhPoRm1ZLvvbXvvGKh9t0BddkCL0udpYMg2Up4rWbcT0H1noqfvjl53FuDTQ

三 通过浏览器访问DashboardUI

登陆IP和对应端口,把token输入

 

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐