2

一、环境介绍

k8s版本:v1.22.2
dashboard版本:v2.5.1
安装前注意k8s的版本与将要安装的dashbaord版本是否兼容,具体查看https://github.com/kubernetes...

二、dashbord安装

下载官方yaml文件并且进行部署

root@master01:~/dashboard# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml
--2023-01-03 20:51:21--  https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7621 (7.4K) [text/plain]
Saving to: ‘recommended.yaml’

recommended.yaml                              100%[=================================================================================================>]   7.44K  --.-KB/s    in 0.004s  

2023-01-03 20:51:22 (1.95 MB/s) - ‘recommended.yaml’ saved [7621/7621]

修改其网络为NodePort模式,方便宿主机进行访问,注意其40行与44行位置内容的变更。

 30 ---
 31 
 32 kind: Service
 33 apiVersion: v1
 34 metadata:
 35   labels:
 36     k8s-app: kubernetes-dashboard
 37   name: kubernetes-dashboard
 38   namespace: kubernetes-dashboard
 39 spec:
 40   type: NodePort
 41   ports:
 42     - port: 443
 43       targetPort: 8443
 44       nodePort: 30001
 45   selector:
 46     k8s-app: kubernetes-dashboard
 47 
 48 ---

部署dashboard

root@master01:~/dashboard# kubectl apply  -f recommended.yaml 
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created

查看dashbaord相关pod状态

root@master01:~/dashboard# kubectl get po -n kubernetes-dashboard 
NAME                                        READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-c45b7869d-rh4p7   1/1     Running   0          4m2s
kubernetes-dashboard-79b5779bf4-bvbsf       1/1     Running   0          4m2s

在宿主机使用浏览器成功访问到dashboard
image.png

将kubernetes-dashboard绑定cluster-admin权限。

root@master01:~/dashboard# kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:kubernetes-dashboard
clusterrolebinding.rbac.authorization.k8s.io/dashboard-cluster-admin created

从默认创建的secret中找到相关的tocken值粘贴到浏览器对应位置,注意kubernetes v1.24.0 更新之后进行创建 ServiceAccount 不会自动生成 Secret 需要对其手动创建本文使用的版本为1.22版本,所以会自动生成Secret。具体说明请查看:https://cloud.tencent.com/dev...

root@master01:~/dashboard# kubectl get secrets -n kubernetes-dashboard 
NAME                               TYPE                                  DATA   AGE
default-token-625rd                kubernetes.io/service-account-token   3      11m
kubernetes-dashboard-certs         Opaque                                0      11m
kubernetes-dashboard-csrf          Opaque                                1      11m
kubernetes-dashboard-key-holder    Opaque                                2      11m
kubernetes-dashboard-token-ffsvd   kubernetes.io/service-account-token   3      11m
root@master01:~/dashboard# kubectl describe secrets kubernetes-dashboard-token-ffsvd  -n kubernetes-dashboard 
Name:         kubernetes-dashboard-token-ffsvd
Namespace:    kubernetes-dashboard
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: kubernetes-dashboard
              kubernetes.io/service-account.uid: 7cd8d6da-b722-4791-b432-b4459d1931c2

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1350 bytes
namespace:  20 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6InpjRXhWTDd6MmlPRmoyS0FEbDVIWFFZb29SaWlkRjlORVNnYm9GUEdKSmMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC10b2tlbi1mZnN2ZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjdjZDhkNmRhLWI3MjItNDc5MS1iNDMyLWI0NDU5ZDE5MzFjMiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDprdWJlcm5ldGVzLWRhc2hib2FyZCJ9.fXJcuj5pwsAf-9_OPY2FXV7Lo5wqcfT-JkqFpIW1SwS0JtTR1ndbjNhZX0Wo5d4ds2ZCSMHnf1V0sII3mzRIF8iYPKiRxRgowEDhPFTW3gOqMaeirmpdAuMT4UcaV6HibH0wIipE74RYiPLMdTC7Y5Mu1sFQO8gKNAHWj3k9mPblVYK9IUYvFiVIJm5UNBVQpvxZYyrjld7v9UCi0RWyHcnNA8DCY6nlbPbyUp7gYwfEGUPeJo_4ewQ4AFktiuTA6lbSWqL1AB8WOzIcEfjCqZaRUbnPKt6HZGNNglCSiRTyHz2maGeH9mqk7cF7vxVQ3uzewGPvOnEOg1SSbkGhUA

在浏览器登录后效果,注意右下角显示的POD的CPU及内存使用监控需要安装metric-server才可以正常显示,否则会显示空白。

image.png

ps:本文操作已在本人环境中操作成功,如有问题亦或表述不清的地方欢迎指正。


李朝阳
52 声望14 粉丝

人生到处知何似,应似飞鸿踏雪泥