赞
踩
Dashboard是k8s集群管理的一个WebUI,它是k8s的一个附加组件,所以需要单独来部署;
我们可以通过图形化的方法,创建、删除、修改、查询k8s资源;
Github地址:GitHub - kubernetes/dashboard: General-purpose web UI for Kubernetes clusters
参考链接:Release v2.5.1 · kubernetes/dashboard · GitHub
可以通过上述地址,查询对应k8s的版本,来下载对应的dashboard;
百度云盘地址:
链接:https://pan.baidu.com/s/14Wu-gRjfDa8IWCawY6O72g?pwd=ni8n
提取码:ni8n
本次学习,我们直接使用我给大家准备好的百度网盘的文件;就不需要大家“越界”下载了;
[root@k8s231 dashboard]# rz -E
[root@k8s231 dashboard]# ll
-rw-r--r-- 1 root root 7660 Jan 6 08:59 dashboard_.yaml
以前修改过的,不用修改,或者你可以不修改,而是修改dashboard的文件中的svc资源的端口范围为30000-32767;
本次学习,我们不修改文件,只修改k8s的svc的nodeport的端口范围;
[root@k8s231 dashboard]# vim /etc/kubernetes/manifests/kube-apiserver.yaml
.............
spec:
containers:
- command:
- kube-apiserver
#下面这一条加进去,就修改完成了;自动就会更新;稍等一会;先会崩溃;
- --service-node-port-range=3000-50000
- --advertise-address=10.0.0.231
......
[root@k8s231 dashboard]# kubectl apply -f dashboard_.yaml
#查看是否有新的名称空间?
[root@k8s231 dashboard]# kubectl get ns
................
kubernetes-dashboard Active 5m58s
#查看,dashboard名称空间下的pod,是否running?
[root@k8s231 dashboard]# kubectl get pods -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-799d786dbf-558zs 1/1 Running 0 6m16s
kubernetes-dashboard-fb8648fd9-twr8k 1/1 Running 0 6m16s
访问:https://10.0.0.231:8443
浏览器会显示不安全的证书链接;点击【高级】也没用,怎么办?
温馨提示:如果打不开网页,可以鼠标单击空白处,,依次输入“thisisunsafe”,即可自动跳转进入页面了;
点击空白处,写上“thisisunsafe”之后,会自动进入登录页面
我们可以看见上图中:有两个登录选项,token登录和kubeconfig登录;
其实就是先查看dashboard的sa用户的详细信息;
我们可以看到,sa用户有一个token字段;这个token字段本质上也是一个secrets资源;
[root@k8s231 dashboard]# kubectl -n kubernetes-dashboard describe sa kubernetes-dashboard | grep Tokens
Tokens: kubernetes-dashboard-token-2rrz9
我们继续查看用户token的secrets资源详细信息,就可以获取到token的详细编码信息了;
[root@k8s231 dashboard]# kubectl -n kubernetes-dashboard describe secrets kubernetes-dashboard-token-2rrz9
.........
token: eyJhbGciOiJSUzI1NiIsImtpZCI6ImhJc3J4Y0JsRGQtWlVDZE9GbDkxQVRMMVJZaUlVNnRxWTFzZFBPdU5hM0kifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC10b2tlbi0ycnJ6OSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjY2NjI1NDZmLTRhOTctNDc5MS04ZGI3LWZhNTFhZTc4M2Y3OCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDprdWJlcm5ldGVzLWRhc2hib2FyZCJ9.KpE4z0IX_404d_YhdjjcrPzlV-IovqhCx8AT9PaswK35q5AYeY6hf_Eu7oXLDiNlnIKVCscEp8BkpWfiTHZsc1Xfbo4Fw-95-aKXYS-ZOOwWF5vY2UjfQ-fbHqo5tbZN04GLzn67xaE096pVXVz6G6JQwGWIqCHFYcQMn_rp_OYOfPG4TkJ3-nMEq3NJB7gYf2X5xmhvMkEOTOgMwbAw-90Sn3EXW1nHhb6KsyWvKpq65qYnioqNu6KgXub1UD6caXWnMpOaaGE29Tm6_r55Hi_fIaLPwbhHUJ3mx7m99unmAiPDh3wsIhBcFYmbSzWJjGyLpzFJEhs-miKYuVpYNQ
点击【登录】虽然登录进来了,但是,显示没有权限;
[root@k8s231 dashboard]# cat sa-dash.yaml
#创建sa用户叫xinjizhiwa
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
# 创建一个名为"xinjizhiwa"的账户
name: xinjizhiwa
namespace: kubernetes-dashboard---
#绑定k8s集群中的最大权限的角色与xinjizhiwa用户
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-oldboyedu
namespace: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
# 既然绑定的是集群角色,那么类型也应该为"ClusterRole",而不是"Role"哟~
kind: ClusterRole
# 关于集群角色可以使用"kubectl get clusterrole | grep admin"进行过滤哟~
name: cluster-admin
subjects:
- kind: ServiceAccount
# 此处要注意哈,绑定的要和我们上面的服务账户一致哟~
name: xinjizhiwa
namespace: kubernetes-dashboard
[root@k8s231 dashboard]# kubectl apply -f sa-dash.yaml
[root@k8s231 dashboard]# kubectl -n kubernetes-dashboard describe sa xinjizhiwa | grep Tokens
Tokens: xinjizhiwa-token-crn87
[root@k8s231 dashboard]# kubectl -n kubernetes-dashboard describe secrets xinjizhiwa-token-crn87
..................
token: eyJhbGciOiJSUzI1NiIsImtpZCI6ImhJc3J4Y0JsRGQtWlVDZE9GbDkxQVRMMVJZaUlVNnRxWTFzZFBPdU5hM0kifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291b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2tlbi0ycnJ6OSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjY2NjI1NDZmLTRhOTctNDc5MS04ZGI3LWZhNTFhZTc4M2Y3OCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlcm5ldGVzLWRhc2hib2FyZDprdWJlcm5ldGVzLWRhc2hib2FyZCJ9.KpE4z0IX_404d_YhdjjcrPzlV-IovqhCx8AT9PaswK35q5AYeY6hf_Eu7oXLDiNlnIKVCscEp8BkpWfiTHZsc1Xfbo4Fw-95-aKXYS-ZOOwWF5vY2UjfQ-fbHqo5tbZN04GLzn67xaE096pVXVz6G6JQwGWIqCHFYcQMn_rp_OYOfPG4TkJ3-nMEq3NJB7gYf2X5xmhvMkEOTOgMwbAw-90Sn3EXW1nHhb6KsyWvKpq65qYnioqNu6KgXub1UD6caXWnMpOaaGE29Tm6_r55Hi_fIaLPwbhHUJ3mx7m99unmAiPDh3wsIhBcFYmbSzWJjGyLpzFJEhs-miKYuVpYNQ"#设置集群
kubectl config set-cluster xinjizhiwa-cluster --server=https://10.0.0.231:6443 --kubeconfig=xjzw.conf#设置客户端
kubectl config set-credentials xinjizhiwa-client --token=${XINJIZHIWA_TOKEN} --kubeconfig=xjzw.conf#集群结合客户端
kubectl config set-context xinjizhiwa-user --cluster=xinjizhiwa-cluster --user=xinjizhiwa-client --kubeconfig=xjzw.conf#声明使用上下文生成kubeconfig文件
kubectl config use-context xinjizhiwa-user --kubeconfig=xjzw.conf
执行脚本生成文件
[root@k8s231 dashboard]# bash kc.sh
[root@k8s231 dashboard]# ll
................
-rw------- 1 root root 1305 Feb 23 03:53 xjzw.conf
导出文件到本地电脑桌面
上传到dashboard页面为止
至此,两种方式的登录,就成功了;
手动编辑资源清单
上传yaml文件创建
至此,dashboard图形化管理工具学习完毕;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。