1、下载yaml文件进行部署
root@master-1:~# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
2、修改service的访问模式
root@master-1:~# vim recommended.yaml kind: Service
apiVersion: v1
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kubernetes-dashboard
spec:ports:- port: 443targetPort: 8443selector:k8s-app: kubernetes-dashboardtype: NodePort #修改为NodePort,没有就添加上
3、创建一个管理员用户
vim admin-user.yaml
apiVersion: v1
kind: ServiceAccount
metadata:name: admin-usernamespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: admin-user
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin
subjects:
- kind: ServiceAccountname: admin-usernamespace: kube-system
4、进行部署验证
kubectl apply -f recommended.yaml admin-user.yaml#检查pod的状态
root@master-1:~# kubectl get po -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-5cb4f4bb9c-m98c7 1/1 Running 0 35m
kubernetes-dashboard-6967859bff-q4plq 1/1 Running 0 35m#查看service的配置(根据自己的端口访问)
root@master-1:~# kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.96.3.11 <none> 8000/TCP 36m
kubernetes-dashboard NodePort 10.96.3.204 <none> 443:31859/TCP 36m#生成token
root@master-1:~# kubectl create token admin-user -n kube-system
拿到token后登录验证