[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
在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
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介面
複製上面生成的令牌
存取成功