前言

上一篇中将k8s简单部署安装上了,这篇接着安装下dashboard。

具体步骤

  1. 下载yaml文件
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml

注意:这里使用的版本是v2.5.0,这个要和k8s的版本匹配上。

  1. 编辑recommended.yaml
    在这里插入图片描述
  2. 启动部署

该命令执行后大约需要1分钟才能部署好

kubectl apply -f recommended.yaml 

查看是否运行

[root@k8s-master home]# kubectl get pod -n kubernetes-dashboard
NAME                                         READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-799d786dbf-xpcnw   1/1     Running   0          2m34s
kubernetes-dashboard-546cbc58cd-p7k52        1/1     Running   0          2m34s
  1. 浏览器打开页面

找到所在Node节点

[root@k8s-master home]# kubectl get pods -o wide -n kubernetes-dashboard
NAME                                         READY   STATUS    RESTARTS   AGE     IP           NODE        NOMINATED NODE   READINESS GATES
dashboard-metrics-scraper-799d786dbf-xpcnw   1/1     Running   0          2m46s   10.244.2.6   k8s-node2   <none>           <none>
kubernetes-dashboard-546cbc58cd-p7k52        1/1     Running   0          2m46s   10.244.2.5   k8s-node2   <none>           <none>

找到Service的端口

[root@k8s-master home]# kubectl get svc -n kubernetes-dashboard
NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
dashboard-metrics-scraper   ClusterIP   10.96.68.30     <none>        8000/TCP        3m8s
kubernetes-dashboard        NodePort    10.100.237.30   <none>        443:32461/TCP   3m8s

在浏览器中的地址就是:https://192.168.1.42:32461
用chrome访问,会出现不安全的网站的提示,随便点击 chrome 空白位置,输入 thisisunsafe 即进入登录界面,如下
在这里插入图片描述

  1. 使用token登录

找到secret名称

[root@k8s-master home]# kubectl get secret -n kubernetes-dashboard
NAME                               TYPE                                  DATA   AGE
default-token-b6hcv                kubernetes.io/service-account-token   3      7m22s
kubernetes-dashboard-certs         Opaque                                0      7m22s
kubernetes-dashboard-csrf          Opaque                                1      7m22s
kubernetes-dashboard-key-holder    Opaque                                2      7m22s
kubernetes-dashboard-token-5zkzt   kubernetes.io/service-account-token   3      7m22s

查看 secret 值

[root@k8s-master home]# kubectl describe secret kubernetes-dashboard-token-5zkzt -n kubernetes-dashboard
Name:         kubernetes-dashboard-token-5zkzt
Namespace:    kubernetes-dashboard
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: kubernetes-dashboard
              kubernetes.io/service-account.uid: f2b95f6c-9bfa-4152-849b-098c4cdc560f

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1099 bytes
namespace:  20 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IjdXTUZBZTNpLVVTcUFYaUluelF6eUdEdVQtV0hid1BXd0h0c0ZGM3BRWUUifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC10b2tlbi01emt6dCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImYyYjk1ZjZjLTliZmEtNDE1Mi04NDliLTA5OGM0Y2RjNTYwZiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDprdWJlcm5ldGVzLWRhc2hib2FyZCJ9.mK1DtG1bcw4UQ_b_CTrkgl-lg7Nxo2TwU_tkBrPAExCCCYSW87pijw3NFMBIiJwuoBA9Czd2O0IwKlObtKaqUMQSbl0NG5CIM1hIYol10oeXdZjD_ldykJPhzR9334KPzyp4_0dIAanfWuK7v_eDnJQfF50YNb_uX-gRVWYKL4jcEaw19WW7nyNuwbjiv4xIzDjCAG4pm4-XsnaIyY83LrOw_UPGEsL0Q3Smjp1hLIVtPX5tc7TFtPHNjYZu8LZIroG6oAFmmmF4xUeLstqvgn-kST8gyMn0VjiGQfECWmpfszfDqqsns6VqdQWSlAa9oCDANd8N4C_rZFxO3PlxYQ

把token拷贝进去,登录即可
在这里插入图片描述

总结

当k8s环境搭建好后,安装dashboard就比较简单了,但当进来后右上角的铃铛会有报错提示,网上给的解决办法是权限问题导致,需要把 kubernetes-dashboard绑定cluster-admin权限。

[root@k8s-master home]# kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:kubernetes-dashboard
error: failed to create clusterrolebinding: clusterrolebindings.rbac.authorization.k8s.io "dashboard-cluster-admin" already exists

然后刷新就好了,但是我执行直接就报错了,但是页面刷新下也就好使。

Logo

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

更多推荐