介绍
之前在kubernetes中完成的所有操作都是通过命令行工具kubectl完成的。其实,为了提供更丰富的用户体验,kubernetes还开发了一个基于web的用户界面(Dashboard)。用户可以使用Dashboard部署容器化的应用,还可以监控应用的状态,执行故障排查以及管理kubernetes中各种资源。
部署Dashboard
- 下载yaml,并运行Dashboard
# 下载yaml [root@master k8sYamlForCSDN]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml ... 2022-03-04 21:14:05 (610 KB/s) - 已保存 “recommended.yaml” [7621/7621]) # 修改kubernetes-dashboard的Service类型,Name为kubernetes-dashboard的地方 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@master ~]# kubectl create -f recommended.yaml # 查看namespace下的kubernetes-dashboard下的资源 [root@master k8sYamlForCSDN]# kubectl get pods,svc -n kubernetes-dashboard NAME READY STATUS RESTARTS AGE pod/dashboard-metrics-scraper-799d786dbf-l8zdd 1/1 Running 0 16s pod/kubernetes-dashboard-546cbc58cd-555fr 1/1 Running 0 16s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/dashboard-metrics-scraper ClusterIP 10.104.170.97 <none> 8000/TCP 16s service/kubernetes-dashboard NodePort 10.104.201.103 <none> 443:30009/TCP 16s # 在浏览器上访问这个网址 https://192.168.109.100:30009/#/login
- 创建访问账户,获取token
# 创建账号 [root@master k8sYamlForCSDN]# kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard serviceaccount/dashboard-admin created # 授权 [root@master k8sYamlForCSDN]# kubectl create clusterrolebinding dashboard-admin-rb --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin-rb created # 获取账号token [root@master k8sYamlForCSDN]# kubectl get secrets -n kubernetes-dashboard | grep dashboard-admin dashboard-admin-token-7b8dc kubernetes.io/service-account-token 3 14s # 查看token [root@master k8sYamlForCSDN]# kubectl describe secrets dashboard-admin-token-7b8dc -n kubernetes-dashboard Name: dashboard-admin-token-7b8dc Namespace: kubernetes-dashboard Labels: <none> Annotations: kubernetes.io/service-account.name: dashboard-admin kubernetes.io/service-account.uid: 9d52e455-d26d-4664-822c-713229249647 Type: kubernetes.io/service-account-token Data ==== ca.crt: 1099 bytes namespace: 20 bytes token: eyJhbGciOiJSUzI1NiIsImtpZCI6Il9FUDBWd3VzbEdfOENLWGV2ZnBYN2l1ZVhkVHRFYjlWY1dtQ0tfMjdXWnMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tN2I4ZGMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiOWQ1MmU0NTUtZDI2ZC00NjY0LTgyMmMtNzEzMjI5MjQ5NjQ3Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmVybmV0ZXMtZGFzaGJvYXJkOmRhc2hib2FyZC1hZG1pbiJ9.njOGlG65zfbdjmYhBiE6tEDTf1CAIcnuF37TeI-tKn7PJoWed8dafNJMQo6D_W4LeKv7NP20UIEk_KhsJXFJoKaThUrPCyqi4SCdq1vZMdHHfJwetDaQZrSBl9FYR8ZKmS5Ym13Wwklq9wh_yWlnKWLaUFxBV2I7LZxwZJKERocFhTlhv96W3NsEPR-TmGxGEvix910BZ4LWx6QfOu5ycIHPparaVlCPCJDoj7za3F-evAEdETja80eWqb62Gc2D8eGntKggHK9gMaGZsSUlhRv1H6jUxxzkHzabxS6lMNMex4u07Rntkqy69Mp_g2sHsYBTnCSjvcPGDAwLz8fQCA