1、安装
方式一
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
方式二
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
kubectl apply -f recommended.yaml
2、暴露端口
kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard
3、查看端口
kubectl get svc -A |grep kubernetes-dashboard
4、访问
https://集群任意IP:端口
https://192.168.211.151:31469
5、创建访问账号
#创建访问账号,准备一个yaml文件; vi dash.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
kubectl apply -f dash.yaml
5、获取访问令牌
kubectl -n kubernetes-dashboard get secret $(kubectl -n kubernetes-dashboard get sa/admin-user -o jsonpath="{.secrets[0].name}") -o go-template="{{.data.token | base64decode}}"
eyJhbGciOiJSUzI1NiIsImtpZCI6InlsSGVVSXBaQ082RTFfZVBYZGlNRk1GdnN2bUZWdGJqWEdQd2lySXN3SUEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLTdmcDZ4Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIwNmIwM2RmYi1hYzNmLTRkNDgtYmYyNC1mM2I3OGQzZDU5ZDUiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.pc3_-rYuSFbVmL0Rk5dKZHeoK6rilYRf05_YFFzkyoLZUS62E5uAVE3ZLn-VMzEAglOAS4clMBX8tNqXNde39AGPAeAsIK6jbuR0mDbIr3PR4k5J8ZHdAdqNiTCUoXRE0DoFh2QaHZCmKx4huC1616QJ98vAelJFspKrnA10K3kEgUTvumcJ1MjVWegC8jWdYCIIfKqwxJAZZeG9tmPGu9rizb7dB5VCmzs6lxE9Inm8iQOfe3nB6UZjdX8vdauWN1gOO49IA5vUaUOYMLAG3He3a2IgaRWkWFdpdudfg-MM2DFbJIdNdjb4AErXhpSEM0_ZE_4uAgKtaqVuX6GAVA
6、用token登录
https://192.168.211.151:31469/