[root@k8s-n1 ~]# cd k8s/
[root@k8s-n1 k8s]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml
[root@k8s-n1 k8s]# 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
#等待安装结束
[root@k8s-n1 k8s]# watch kubectl get pod -n kubernetes-dashboard -o wide
[root@k8s-n1 k8s]# vim dash-auth.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard
[root@k8s-n1 k8s]# kubectl apply -f dash-auth.yaml
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
[root@k8s-n1 k8s]# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
Name: admin-user-token-v4vxg
Namespace: kubernetes-dashboard
Labels: <none>
Annotations: kubernetes.io/service-account.name: admin-user
kubernetes.io/service-account.uid: c5085cbf-894f-4753-807d-2c432eb3cbe9
Type: kubernetes.io/service-account-token
Data
====
namespace: 20 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IkpLSGJWdkgxR0tELTItS25MZUotb2FNMDA5aXI0T3VudDVqYmFhNENXZncifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXY0dnhnIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiJjNTA4NWNiZi04OTRmLTQ3NTMtODA3ZC0yYzQzMmViM2NiZTkiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.TJuAwClSPT6c7rkSngShdLYeXPa_S1ufQ5mThst_CtfIuNeTHC_KLVdCGaH1wDTigWAACws_D0ZJGFXoXhhbAR4W4EsMtH7usJpK0CvxQJ4BmURueCqSeKAXSw1Lb40ZYzTA4bZzl4JCBVfWl9SJuuIxCEXhiX5CE_2dBPcyvxT_QCqrmMibNPe5lH6RJ7MfEQRUEWqi2Hnyxpp7TLc8ugZ0R-NjQWig6Qif1MiRUPHwH7Y5Q4XvyO_X1fWnIEGJ6_LFzXmvzXsL27S9nElFfIL7aL_uX2tJAf5p3odOLejfMUc6TvJZhf92x1hEAPDXBEMOG4E4jia3JaipesXC2g
ca.crt: 1025 bytes
下载地址: https://storage.googleapis.com/kubernetes-release/release/v1.18.2/bin/windows/amd64/kubectl.exe
将kubectl.exe的目录配置windows的path环境变量中(cmd可以使用kubectl命令)。
[root@k8s-n1 k8s]# cat /etc/kubernetes/admin.conf 将admin.conf的内容配置到windows用户C:\Users\Administrator.kube\config 中 同时配置本机的C:\Windows\System32\drivers\etc\hosts文件能够解析k8s-apiserver的IP地址(增加192.168.0.125 k8s-apiserver,根据自己的IP与apiservername配置)
运行kubectl proxy
C:\Users\Administrator>kubectl proxy
Starting to serve on 127.0.0.1:8001
通过浏览器访问dashboard
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
选择TOKEN登陆
输入前面命令输出的token即可。