一. 下载原yaml文件
- 前往Releases · kubernetes/dashboard · GitHub查看对应dashboard版本
kubelet --version
- 下载yaml文件,可参考官方给出的方式,如果不能下载,可以先用VPN打开链接查看raw后复制到服务器上
cat recommended.yaml
- 执行部署
kubectl apply -f recommended.yaml
- 查看,成功创建
kubectl get pods --all-namespaces
二. 更改服务
- 删除现有的dashboard服务,dashboard 服务的 namespace 是 kubernetes-dashboard,但是该服务的类型是ClusterIP,不便于我们通过浏览器访问,因此需要改成NodePort型的
kubectl get svc --all-namespaces
kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard
- 创建配置文件
vim dashboard-svc.yaml
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
vim dashboard-svc-account.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard-admin
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: dashboard-admin
subjects:
- kind: ServiceAccount
name: dashboard-admin
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
vim serect.yaml
apiVersion: v1
kind: Secret
type: kubernetes.io/service-account-token
metadata:
name: dashboard-admin
namespace: kube-system
annotations:
kubernetes.io/service-account.name: "dashboard-admin"
- 部署
kubectl apply -f dashboard-svc.yaml
kubectl apply -f dashboard-svc-account.yaml
kubectl apply -f serect.yaml
- 查看服务
kubectl get svc --all-namespaces
三. 访问
- 获取token
kubectl get secret -n kube-system |grep admin|awk '{print $1}'
kubectl describe secret <serect名字> -n kube-system|grep '^token'|awk '{print $2}'
- 记下token
eyJhbGciOiJSUzI1NiIsImtpZCI6Im1Nd2RuSlJWZ2FoUC1UR2ZNWmJqUnoyOFBnZ1RaR20wT1EzZGttSWZaNEUifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4iLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNDNmYTkwOGYtNWFhNy00MTcyLWI5NTktYjYxZGZiMjIxYWViIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.ZCcXdqO1rIAMKr5hRMUOYXWsxCL4Tw2CXHg49WOqzvDGWO46Xh96H1Hr54VQ_MxypGbQMIKxCy_aa8ni03JM2d01GvWMqVd-gtQWPkVhNAI2NcaNhvZ-mhXWGhrf59T4lxswkD0V0gOSUhElok8V4vFUeXa8ssAM_liyf2Z9PMEAsqa9qryL1UixPjEvWnHjGLG94hNAYEo-H0sYwoF6eRZkOvvlsRj2CwFviuWPSdaNFWDEiQqkSDxtHROkfhAwPddYqeu7DKBhoW4iRw2-Kbd1z2w0tWXjf6zZkObV1ayP4tYLzIdHi-AwrBmL3214T-fqfqQJhwPmizVI-cL3Hw
- 访问https://ip:port,网关端口映射到NodePort提供的端口号,注意要用https进行访问
kubectl get svc --all-namespaces
四. 参考
K8S 安装 Dashboard_tom马的博客-CSDN博客_k8s安装dashboard