五分钟带你玩转k8s(四)可视化界面Dashboard创建

1.安装

//选择文件夹 下载recommended.yaml到文件夹中
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml
修改下载的文件
vi recommended.yaml

此处需要修改 否者外网访问不到

五分钟带你玩转k8s(四)可视化界面Dashboard创建_第1张图片

将 Dashboard添加至k8s

kubectl apply -f recommended.yaml

查询安装情况

kubectl -n kubernetes-dashboard  get all  -l k8s-app=kubernetes-dashboard

五分钟带你玩转k8s(四)可视化界面Dashboard创建_第2张图片

可以看到启动后的端口 可以使用以下命令测试访问

kubectl -n kubernetes-dashboard port-forward pod/kubernetes-dashboard-5c785c8bcf-z94nt  32241 //访问

pod/kubernetes-dashboard-5c785c8bcf-z94nt与端口都是上文获取 根据自己搭建情况修改

创建用户 否则访问后 看不到具体信息 或者报错(statefulsets.apps is forbidden: User "system:serviceaccount:kubernetes-dashb.......) 如果出现此错误 肯定是用户问题

#创建dashboard-admin账户
kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard
#将dashboard-admin用户授cluster-admin权限(clusterrole为集群管理权限)
kubectl create clusterrolebinding dashboard-admin-rb --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin
#获取账号token
kubectl get secrets -n kubernetes-dashboard |grep dashboard-admin
通过账号获取token(此处dashboard-admin-token-xxxx为上文获取)
kubectl describe secrets dashboard-admin-token-xxxx -n kubernetes-dashboard

五分钟带你玩转k8s(四)可视化界面Dashboard创建_第3张图片

访问 ip:32241(端口每个人都不同 根据上文获取) 我们使用token 登录

五分钟带你玩转k8s(四)可视化界面Dashboard创建_第4张图片

 

 

token为上图获取

2.删除Dashboard

kubectl get secret,sa,role,rolebinding,services,deployments --namespace=kubernetes-dashboard | grep dashboard

kubectl delete deployment kubernetes-dashboard --namespace=kubernetes-dashboard  
kubectl delete service kubernetes-dashboard  --namespace=kubernetes-dashboard 
kubectl delete role kubernetes-dashboard-minimal --namespace=kubernetes-dashboard
kubectl delete rolebinding kubernetes-dashboard-minimal --namespace=kubernetes-dashboard
kubectl delete sa kubernetes-dashboard --namespace=kubernetes-dashboard
kubectl delete secret kubernetes-dashboard-certs --namespace=kubernetes-dashboard
kubectl delete secret kubernetes-dashboard-key-holder --namespace=kubernetes-dashboard

3.查看安装日志

sudo kubectl logs kubernetes-dashboard-6dccb458d5-x7xft --namespace=kubernetes-dashboard

 

你可能感兴趣的:(五分钟带你玩转k8s)