一、下载所需yaml文件安装dashboard(可以直接下载文件)
powershell
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
1、修改 recommended.yaml
yaml
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
type: NodePort #第一个service下方修改类型
ports:
- port: 443
targetPort: 8443
二、登录dashboard
1、创建k8s管理员用户
powershell
kubectl create serviceaccount dashboard-admin -n kube-system
2、权限设置
powershell
kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
3、token生成
powershell
kubectl -n kube-system create token dashboard-admin
kubectl -n kube-system create token dashboard-admin --duration=86400s # 设置过期时间