1 [root@master ~]# mkdir dashboard #建議將yaml存儲到本地 2 [root@master ~]# cd dashboard/ 3 [root@master dashboard]# wget https://raw.githubusercontent.com/kubernetes/dashboard/master/aio/deploy/recommended/kubernetes-dashboard.yaml
1 [root@master ~]# cd dashboard/ 2 [root@master dashboard]# vi kubernetes-dashboard.yaml 3 …… 4 image: mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.1 5 ……
1 [root@master dashboard]# kubectl apply -f kubernetes-dashboard.yaml 2 [root@master ~]# kubectl get pod --all-namespaces -o wide| grep kubernetes-dashboard #確認驗證 3 kube-system kubernetes-dashboard-68ddcc97fc-c5thv 0/1 Running 0 30s <none> node2 <none> <none>
1 [root@master ~]# kubectl proxy 2 [root@master ~]# curl http://127.0.0.1:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/ #訪問
1 [root@master ~]# nohup kubectl proxy --address='0.0.0.0' --accept-hosts='^*$' &
1 [root@master ~]# kubectl -n kube-system edit service kubernetes-dashboard 2 …… 3 type: NodePort 4 …… 5 #將type: ClusterIP 修改成 type: NodePort。
1 [root@master ~]# kubectl get pods --namespace=kube-system | grep dashboard 2 kubernetes-dashboard-68ddcc97fc-c5thv 1/1 Running 0 3h14m 3 [root@master ~]# kubectl describe pod kubernetes-dashboard-68ddcc97fc-c5thv --namespace=kube-system | grep Node 4 Node: node2/172.24.8.73
1 [root@master ~]# mkdir /etc/kubernetes/dash_pki 2 [root@master ~]# cd /etc/kubernetes/dash_pki/ 3 [root@master dash_pki]# openssl genrsa -out ca.key 2048 #生成一個 2048 bit 的 ca.key 4 [root@master dash_pki]# openssl req -x509 -new -nodes -key ca.key -subj "/CN=172.24.8.71" -days 10000 -out ca.crt #根據 ca.key 生成一個 ca.crt(使用 -days 設置證書的有效時間) 5 [root@master dash_pki]# openssl genrsa -out server.key 2048 #生成一個 2048 bit 的 server.key 6 [root@master dash_pki]# openssl req -new -key server.key -subj "/CN=172.24.8.71" -out server.csr #根據 server.key 生成一個 server.csr 7 [root@master dash_pki]# openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 10000 #根據 ca.key、ca.crt 和 server.csr 生成 server.crt 8 subject=/CN=172.24.8.71 9 Getting CA Private Key 10 [root@master dash_pki]# openssl x509 -noout -text -in ./server.crt #查看證書
1 [root@master ~]# cd dashboard/ 2 [root@master dashboard]# kubectl delete -f kubernetes-dashboard.yaml #刪除使用默認證書所建立的dashboard 3 [root@master dashboard]# ll /etc/kubernetes/dash_pki/ 4 [root@master dashboard]# kubectl create secret generic kubernetes-dashboard-certs --from-file="/etc/kubernetes/dash_pki/server.crt,/etc/kubernetes/dash_pki/server.key" -n kube-system #掛載新證書到dashboard 5 [root@master dashboard]# kubectl get secret kubernetes-dashboard-certs -n kube-system -o yaml #查看新證書
1 [root@master dashboard]# kubectl apply -f kubernetes-dashboard.yaml 2 [root@master dashboard]# kubectl get pods --namespace=kube-system | grep dashboard #確認驗證
附001:導出當前Kubernetes證書node