k8s多節點儀表盤(web介面)部署與谷歌瀏覽器訪問k8s儀表盤問題解決!

黎明穿過冰冷的峽谷發表於2020-10-09

k8s的WEB介面部署

兩個master節點檢查pod資源是否正常

[root@localhost ~]# kubectl get nodes  '//檢查node節點是否執行正常'
NAME             STATUS   ROLES    AGE   VERSION
192.168.136.30   Ready    <none>   15h   v1.12.3
192.168.136.40   Ready    <none>   15h   v1.12.3
[root@master ~]# kubectl get pods	'//檢查之前建立的pod資源是否執行正常'
NAME                    READY   STATUS    RESTARTS   AGE
nginx-dbddb74b8-5s6h7   1/1     Running   0          7d8h

master節點上建立dashboard工作目錄,並拷貝部署web介面所需的檔案到指定目錄

  • 下載的網址(直接複製即可):https://github.com/kubernetes/kubernetes/tree/master/cluster/addons/dashboard

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-NhajZWOl-1602208622693)(C:\Users\19437\AppData\Roaming\Typora\typora-user-images\image-20201009085433309.png)]

在master01上操作

建立dashborad工作目錄

[root@localhost k8s]# mkdir dashboard

[root@localhost k8s]# cd /root/k8s/dashboard/
[root@localhost dashboard]# ls
dashboard-configmap.yaml   dashboard-rbac.yaml    dashboard-service.yaml
dashboard-controller.yaml  dashboard-secret.yaml  k8s-admin.yaml

configmap.yaml:配置,deployment.yaml:控制器,rbac.yaml:角色控制,訪問控制,secret.yaml:安全,service.yaml:服務’

我們檢視一下里面的內容

[root@localhost dashboard]# vim dashboard-rbac.yaml 

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-JCHnJB6B-1602208622701)(C:\Users\19437\AppData\Roaming\Typora\typora-user-images\image-20201009092006493.png)]

建立資源(順序不可以亂)

1:建立rbac.yaml:角色控制

[root@localhost dashboard]# kubectl create -f dashboard-rbac.yaml 

2:建立secret.yaml:安全

[root@localhost dashboard]# kubectl create -f dashboard-secret.yaml

3:建立configmap.yaml:配置

[root@localhost dashboard]# kubectl create -f dashboard-configmap.yaml 

4:建立controller

[root@localhost dashboard]# kubectl create -f dashboard-controller.yaml 

5:建立service

[root@localhost dashboard]# kubectl create -f dashboard-service.yaml

檢視資源是否被建立

[root@localhost dashboard]# kubectl get pods -n kube-system
NAME                                    READY   STATUS    RESTARTS   AGE
kubernetes-dashboard-7dffbccd68-jmbgg   1/1     Running   1          10h

檢視所有建立的資源

[root@localhost dashboard]# kubectl get role -n kube-system
[root@localhost dashboard]# kubectl get Secret -n kube-system
[root@localhost dashboard]# kubectl get ConfigMap -n kube-system
[root@localhost dashboard]# kubectl get  ServiceAccount -n kube-system
[root@localhost dashboard]# kubectl get Service -n kube-system 

檢視server資源和pods資源

kubectl get pods,svc -n kube-system

檢視地址

 kubectl get pods -n kube-system -o wide(檢視pod資源)
 kubernetes-dashboard-7dffbccd68-jmbgg   1/1     Running   1          10h   172.17.38.2   192.168.136.40   <none>

訪問https://192.168.136.40:300001這裡是無法訪問的

在這裡插入圖片描述

谷歌瀏覽器無法訪問的問題解決

建立簽名證書

[root@localhost dashboard]# vim dashboard-cert.sh
cat > dashboard-csr.json <<EOF
{
   "CN": "Dashboard",
   "hosts": [],
   "key": {
       "algo": "rsa",
       "size": 2048
   },
   "names": [
       {
           "C": "CN",
           "L": "BeiJing",
           "ST": "BeiJing"
       }
   ]
}
EOF

K8S_CA=$1
cfssl gencert -ca=$K8S_CA/ca.pem -ca-key=$K8S_CA/ca-key.pem -config=$K8S_CA/ca-config.json -profile=kubernetes dashboard-csr.json | cfssljson -bare dashboard

建立證書

先刪除資源
kubectl delete secret kubernetes-dashboard-certs -n kube-system
建立證書
kubectl create secret generic kubernetes-dashboard-certs --from-file=./ -n kube-system

執行指令

bash dashboard-cert.sh /root/k8s/k8s-cert/

自簽證書

[root@localhost dashboard]# vim dashboard-controller.yaml

 47           - --auto-generate-certificates 下面新增
 48        -    --tls-key-file=dashboard-key.pem
 49           - --tls-cert-file=dashboard.pem

在這裡插入圖片描述

重新部署

 kubectl apply -f dashboard-controller.yaml

如果上面命令無法操作請嘗試下面

 kubectl delete -f dashboard-controller.yaml
 kubectl create -f dashboard-controller.yaml

在次訪問出現點選繼續訪問
在這裡插入圖片描述

生成令牌

[root@localhost dashboard]# kubectl create -f k8s-admin.yaml 

儲存

[root@localhost dashboard]# kubectl get secret -n kube-system
NAME                               TYPE                                  DATA   AGE
dashboard-admin-token-gxfmr        kubernetes.io/service-account-token   3      34s
default-token-zpjbp                kubernetes.io/service-account-token   3      6h9m
kubernetes-dashboard-certs         Opaque                                11     7m24s
kubernetes-dashboard-key-holder    Opaque                                2      3h53m
kubernetes-dashboard-token-qjkln   kubernetes.io/service-account-token   3      3m58s

檢視令牌

[root@localhost dashboard]# kubectl describe secret dashboard-admin-token-gxfmr -n kube-system

複製命令
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tZ3hmbXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNjgwOTJkZTAtMDk3OC0xMWViLTljZWItMDAwYzI5MmU3ZWY0Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.ksTrreEa-yJYx1YxQTm-IQ7wanV4zMqfLqvkwPuYAq8fsR40hKufY7l0UPp9Z6bTRWydNtqWBdgGdJGnzstNHR11g5xEFvE4RGqBbcowLqXGofIBCx-axMWdy6eFLmScrUKOjfK-0v5QP9RxoIawVqmhiWTKezfsmft474psjfQpQCNxPsuwASejEHhFI8NOZtXMLYQj1k_L_zS8FhskvpZkJ7VZo6r4O8HZcrgbGuB57_9eTpdl0Y8qB88ADHGXcwor-Kii4mtmS3XNNPWf0XfvYd22Y-AFrfx3g7l2ssTuJkNjo6osfK5hkGjf8etPyNtD7KUArooFE2rUE7bN4Q

再次訪問web介面

選擇使用令牌訪問

複製上面生成的令牌

[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片儲存下來直接上傳(img-kpYvQbFU-1602208622715)(C:\Users\19437\AppData\Roaming\Typora\typora-user-images\image-20201009094522793.png)]

訪問成功

在這裡插入圖片描述

相關文章