部署kubernetes-dashboard
导入yaml文件及镜像
解压镜像
docker load -i dashboard.tar
docker load -i metrics.tar
如果有镜像仓库时可以将解压的镜像推到仓库,没有可以将镜像解压到node节点(如果节点过多,可以通过添加node标签的方式将pod固定在某几台node上,再在对应的node上解压镜像即可)
执行yaml文件
[root@master dashboard]# 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
修改server的暴露端口方式
需要能外部访问,修改为nodeport类型
kubectl patch svc kubernetes-dashboard -p '{"spec":{"type":"NodePort"}}' -n kubernetes-dashboard
找到暴露端口
kubectl get svc -n kubernetes-dashboard
通过节点IP+暴露的端口访问
获取token
先创建secret
kubectl apply -f admin-role.yaml
找到secret
[root@gs-server-10628 ~]# kubectl -n kube-system get secret|grep admin-token
admin-token-nxjxr kubernetes.io/service-account-token 3 32d
获取token
[root@gs-server-10628 ~]# kubectl -n kube-system describe secret admin-token-nxjxr
Name: admin-token-nxjxr
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name: admin
kubernetes.io/service-account.uid: d0d2c8a1-16c1-11ec-b664-00155d3c3900
Type: kubernetes.io/service-account-token
Data
====
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi10b2tlbi1ueGp4ciIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJhZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6ImQwZDJjOGExLTE2YzEtMTFlYy1iNjY0LTAwMTU1ZDNjMzkwMCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTphZG1pbiJ9.THtkhrkUdD1M4Nb4ZD2BOmtmQJlOCwPkbbVm9d2LH1J06L57lsSxSvR9-y1v1RQ80otjZw_uOJt2xhxka9wmVMc26dhbd4rsc5Juzl8Vx9Y5D67xCYIYXqusReeNCkmEScBDK4POcZSPpJprYuB0fcFP9Dnwzu-sSRJRVPD-pPqbD_ckVpmUhPscK8mFDX70fzYKvx_y2Ar3PgRFhprC1ibAG3ZO8SCHqqv7C3pPuDGOEag24HMCkfToe_xntXlsqsEPemLAsctVRjoS3VLLVnIKpm0cetSvzRSQxdeixC5m0b0PuiZHfToZNHxZQBYG8cIqc5DsyD-KeVROz2vEDQ
ca.crt: 1029 bytes
namespace: 11 bytes
将token输入就可以正常访问了。