CC00039.CloudKubernetes——|KuberNetes&二进制部署.V17|5台Server|——|kubernetes组件|dashboard|

一、部署dashboard

1### --- Dashboard概述 2 3~~~ Dashboard用于展示集群中的各类资源, 4~~~ 同时也可以通过Dashboard实时查看Pod的日志和在容器中执行一些命令等。 5
1### --- 安装指定版本dashboard 2~~~ # 切换到dashboard部署目录下 3 4[root@k8s-master01 ~]# cd /root/k8s-ha-install/dashboard/ 5
1~~~ # 部署dashboard 2 3[root@k8s-master01 dashboard]# kubectl create -f . 4~~~ 注:输出结果: 5serviceaccount/admin-user created 6clusterrolebinding.rbac.authorization.k8s.io/admin-user created 7namespace/kubernetes-dashboard created 8serviceaccount/kubernetes-dashboard created 9service/kubernetes-dashboard created 10secret/kubernetes-dashboard-certs created 11secret/kubernetes-dashboard-csrf created 12secret/kubernetes-dashboard-key-holder created 13configmap/kubernetes-dashboard-settings created 14role.rbac.authorization.k8s.io/kubernetes-dashboard created 15clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created 16rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created 17clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created 18deployment.apps/kubernetes-dashboard created 19service/dashboard-metrics-scraper created 20deployment.apps/dashboard-metrics-scraper created 21
1### --- 查看dashboard.pod状态 2~~~ # 查看dashboard部署运行结果 3 4[root@k8s-master01 dashboard]# kubectl get po -n kubernetes-dashboard 5NAME READY STATUS RESTARTS AGE 6dashboard-metrics-scraper-7645f69d8c-7dd2b 1/1 Running 0 2m24s 7kubernetes-dashboard-78cb679857-mqccg 1/1 Running 0 2m25s 8

二、登录dashboard-UI

1### --- Chrome客户端配置 2 3~~~ 在谷歌浏览器(Chrome)启动文件中加入启动参数,用于解决无法访问Dashboard的问题: 4~~~ --test-type --ignore-certificate-errors 5
1### --- 查看dashboard.service端口号 2~~~ # 更改dashboard的svc为NodePort: 3~~~ 注:将ClusterIP更改为NodePort(如果已经为NodePort忽略此步骤)4 5[root@k8s-master01 dashboard]# kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard 6 type: NodePort 7
1~~~ # 查看端口号 2 3[root@k8s-master01 dashboard]# kubectl get svc kubernetes-dashboard -n kubernetes-dashboard 4NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 5kubernetes-dashboard NodePort 10.104.232.53 <none> 443:30008/TCP 5m26s 6
1### --- 查看dashboard-token值 2~~~ # 查看token值 3 4[root@k8s-master01 dashboard]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}') 5Name: admin-user-token-nh8n7 6Namespace: kube-system 7Labels: <none> 8Annotations: kubernetes.io/service-account.name: admin-user 9 kubernetes.io/service-account.uid: cc002287-5bd5-4e09-9b87-bfe1ea9d6d1f 10 11Type: kubernetes.io/service-account-token 12 13Data 14==== 15namespace: 11 bytes 16token: eyJhbGciOiJSUzI1NiIsImtpZCI6InQ2ci1YY3cwaTZjVlQ2bzhaeTJiaGhMNE1fblFzMExrWDhOd25PZmFMXzAifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLW5oOG43Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjYzAwMjI4Ny01YmQ1LTRlMDktOWI4Ny1iZmUxZWE5ZDZkMWYiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.AkpCaM-gosJ_v_oZJoym3DcgT4qcSlBEsxDZOpqaRLJrF0LTb6ncEFey5MRMXXTEruCnocssuZtb7nuumw2jMgJtEpUsYhhz52ft7aEji8jKRP5-oFBnjX1h1F-vGNupvXq7hZ8CKaK-rGiI40cp8MQAVC8YLpmfGdCSnxDlxiN2DnsqIa6yN5yY0CC3J5dT_4du9oKezujyOi0L0V6f2jCtoWYFfCyTZNspmdSfthVhQQCX3SmlEoh4-mTulem8Ng0TC5Gj-VjVGCbQnZwwKT9dyuu4j0s9rfOjElMTIgBNkwiQ-T6kZB8u2MNroGV5kJjlfB_4l5atDia0YtmD2Q 17ca.crt: 1411 bytes 18

三、登录dashboard:

1### --- 登录dashboard: 2~~~ # 将token值输入到令牌后,单击登录即可访问Dashboard 3 4~~~ 根据实例端口号,通过任意安装了kube-proxy的宿主机或者VIP的IP+端口即可访问到dashboard: 5~~~ 访问Dashboard:https://192.168.1.11:30008(请更改30008为自己的端口)6~~~ http://192.168.1.20:30008/;若是http会报错,改为https 7~~~ Client sent an HTTP request to an HTTPS server. 8~~~ 选择登录方式为令牌:即token方式 9

四、部署最新版本的dashboar

1### --- 部署最新版本的dashboard 2 3~~~ # dashboard官方GitHub地址:https://github.com/kubernetes/dashboard 4~~~ 可以在官方dashboard查看到最新版dashboard 5

1### --- 安装最新版本dashboard 2 3[root@k8s-master01 ~]# kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml 4
1### --- 创建dashboard管理员用户 2~~~ # 创建dashboard管理员用户配置文件 3 4[root@k8s-master01 ~]# vim admin.yaml 5apiVersion: v1 6kind: ServiceAccount 7metadata: 8 name: admin-user 9 namespace: kube-system 10--- 11apiVersion: rbac.authorization.k8s.io/v1 12kind: ClusterRoleBinding 13metadata: 14 name: admin-user 15 annotations: 16 rbac.authorization.kubernetes.io/autoupdate: "true" 17roleRef: 18 apiGroup: rbac.authorization.k8s.io 19 kind: ClusterRole 20 name: cluster-admin 21subjects: 22- kind: ServiceAccount 23 name: admin-user 24 namespace: kube-system 25
1~~~ # 创建dashboard管理员用户 2 3[root@k8s-master01 ~]# kubectl apply -f admin.yaml -n kube-system 4

代码交流 2021