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

#下载
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.1.0/aio/deploy/recommended.yaml

官方的kubernetes-dashboard.yaml文件中service的type类型为clusterIp(service默认类型),这种方式要访问dashboard需要通过代理,所以我们改为NodePort方式,这样部署完后,就可以直接通过

nodeIP:port的方式访问
spec:
  type: NodePort  #添加
  ports:
    - nodePort: 30009  #添加
      port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard

查看

kubectl get pod,svc -n kubernetes-dashboard -o wide
NAME                                             READY   STATUS    RESTARTS   AGE   IP           NODE    NOMINATED NODE   READINESS GATES
pod/dashboard-metrics-scraper-79c5968bdc-svtln   1/1     Running   0          57m   10.244.1.2   node1   <none>           <none>
pod/kubernetes-dashboard-7448ffc97b-bfphw        1/1     Running   0          57m   10.244.2.2   node2   <none>           <none>

NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE   SELECTOR
service/dashboard-metrics-scraper   ClusterIP   10.109.35.215    <none>        8000/TCP   57m   k8s-app=dashboard-metrics-scraper
service/kubernetes-dashboard        ClusterIP   10.106.150.154   <none>        443/TCP    57m   k8s-app=kubernetes-dashboard

然后创建账户,获取token

#创建账户
kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard
#授权
kubectl create clusterrolebinding dashboard-admin-rb --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin
#获取账号token
kubectl get secrets -n kubernetes-dashboard |grep dashboard-admin
kubectl describe secrets dashboard-admin-token-2bddq -n kubernetes-dashboard

eyJhbGciOiJSUzI1NiIsImtpZCI6Im5ucnN2aFAzWDlZVWVIdHF6VVpKQnB6R0dIcDBObVVudERfRWpETTBLX0kifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tMmJkZHEiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZDJkM2U4OTYtZjNjZS00ZmY1LWJlMDItYjM5ZjJiYzcxNTBmIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmVybmV0ZXMtZGFzaGJvYXJkOmRhc2hib2FyZC1hZG1pbiJ9.aHlsQdPTYTCoiAOoMw34TaIyg60_d3yWeZrYZaB_l9HvH4-NAGr0Blq7CCQNgjfO8s-HDw-bz_2X1C1ha2hvTgJGYeEH3jtTydQR-nSR-U7DQW6Fj2wlvZT4jHrQqhUCFdHFKptPlNm0_p_UZPIettaFB4c_nYebqOXK8kDabIl_2xkuPDmoGdQAjmIGuO7UrJQSL7dK05MI_hZh0bFzDBpn39PGnwReqgvAMkzYaKGxaGaw6tS1nkRp176cb53L4zRfS3CIc2rDW3RaVZ4RrrpoL0dv1CXtFfADqQf2jYvQgb1pSKwWGqF1VRVZ4GYQk-WNkfxX4DYQ4IL6D_UMJA

在这里插入图片描述

#浏览器访问(用从node节点访问)
https://10.0.0.17:30009
Logo

开源、云原生的融合云平台

更多推荐