Kubernetes Dashboard部署安装
时间:2024-03-31 20:50:53 来源:网络cs 作者:康由 栏目:建站工具 阅读:
目录
Dashboard
官方文档:部署和访问 Kubernetes 仪表板(Dashboard) | Kubernetes
参考文档:(120条消息) K8S 安装 Dashboard_k8s 安装dashboard_tom.ma的博客-CSDN博客
扩展:
K8S 安装 Dashboard
1、在 master 节点执行
1.1、下载recommended.yaml(可能需要翻墙才能下载)
1.2、创建 pod
2、查看dashboard是否成功创建
3、 删除现有的dashboard服务,dashboard 服务的 namespace 是 kubernetes-dashboard,但是该服务的类型是ClusterIP(只能本机访问,不能外网访问),不便于我们通过浏览器访问,因此需要改成NodePort(发布出去)型的
3.1、查看现有的所有服务,并删除kubernetes-dashboard的服务
4、创建配置文件,并执行后查看效果
5、想要访问dashboard服务,就要有访问权限,创建kubernetes-dashboard管理员角色
6、获取 token
7、访问dashboard
8、输入上面获得的token,然后登录
Dashboard
dashboard 仪表盘--》理解为图形界面展示各种数据--》web界面显示各种图表
跟grafana差不多
官方文档:部署和访问 Kubernetes 仪表板(Dashboard) | Kubernetes
参考文档:(120条消息) K8S 安装 Dashboard_k8s 安装dashboard_tom.ma的博客-CSDN博客
扩展:
kuboard也是一个k8s的仪表盘,可以看到k8s里的资源对象的信息
参考文章:安装 Kuboard v3 - kubernetes | Kuboard
k8s部署promethes
参考文章:
Kubernetes运维之使用Prometheus全方位监控K8S_51CTO博客_prometheus如何监控k8s
K8S 安装 Dashboard
1、在 master 节点执行
1.1、下载recommended.yaml(可能需要翻墙才能下载)
[root@master ~]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml--2023-07-13 22:30:50-- https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.110.133, 185.199.111.133, ...正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:7621 (7.4K) [text/plain]正在保存至: “recommended.yaml”100%[===================================================================================================================================================>] 7,621 28.4KB/s 用时 0.3s 2023-07-13 22:30:52 (28.4 KB/s) - 已保存 “recommended.yaml” [7621/7621])[root@master ~]# lsanaconda-ks.cfg recommended.yaml[root@master ~]#
1.2、创建 pod
[root@master ~]# kubectl apply -f recommended.yamlnamespace/kubernetes-dashboard createdserviceaccount/kubernetes-dashboard createdservice/kubernetes-dashboard createdsecret/kubernetes-dashboard-certs createdsecret/kubernetes-dashboard-csrf createdsecret/kubernetes-dashboard-key-holder createdconfigmap/kubernetes-dashboard-settings createdrole.rbac.authorization.k8s.io/kubernetes-dashboard createdclusterrole.rbac.authorization.k8s.io/kubernetes-dashboard createdrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard createdclusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard createddeployment.apps/kubernetes-dashboard createdservice/dashboard-metrics-scraper createddeployment.apps/dashboard-metrics-scraper created[root@master ~]#
2、查看dashboard是否成功创建
[root@master ~]# kubectl get pods --all-namespacesNAMESPACE NAME READY STATUS RESTARTS AGEdefault php-apache-779bc4fcc9-4ct7p 1/1 Running 0 20mkube-flannel kube-flannel-ds-6swk8 1/1 Running 0 22mkube-flannel kube-flannel-ds-dvpv4 1/1 Running 0 22mkube-flannel kube-flannel-ds-kl2nd 1/1 Running 0 22mkube-flannel kube-flannel-ds-t5lxb 1/1 Running 0 22mkube-system coredns-6d8c4cb4d-h5n8s 1/1 Running 0 24mkube-system coredns-6d8c4cb4d-vttkv 1/1 Running 0 24mkube-system etcd-master 1/1 Running 64 24mkube-system kube-apiserver-master 1/1 Running 70 24mkube-system kube-controller-manager-master 1/1 Running 28 24mkube-system kube-proxy-6b6x6 1/1 Running 0 24mkube-system kube-proxy-bdlf2 1/1 Running 0 24mkube-system kube-proxy-m88cm 1/1 Running 0 24mkube-system kube-proxy-ws5mn 1/1 Running 0 24mkube-system kube-scheduler-master 1/1 Running 24 24mkubernetes-dashboard dashboard-metrics-scraper-6f669b9c9b-8mssp 1/1 Running 0 86skubernetes-dashboard kubernetes-dashboard-758765f476-8dxfm 0/1 ContainerCreating 0 86s[root@master ~]#
3、 删除现有的dashboard服务,dashboard 服务的 namespace 是 kubernetes-dashboard,但是该服务的类型是ClusterIP(只能本机访问,不能外网访问),不便于我们通过浏览器访问,因此需要改成NodePort(发布出去)型的
3.1、查看现有的所有服务,并删除kubernetes-dashboard的服务
[root@master ~]# kubectl get svc --all-namespacesNAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdefault kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 26mdefault php-apache ClusterIP 10.13.85.102 <none> 80/TCP 21mkube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 26mkubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.15.138.130 <none> 8000/TCP 3mkubernetes-dashboard kubernetes-dashboard ClusterIP 10.15.187.146 <none> 443/TCP 3m1s[root@master ~]# kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard #删除现有的服务service "kubernetes-dashboard" deleted[root@master ~]# kubectl get svc --all-namespacesNAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdefault kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 26mdefault php-apache ClusterIP 10.13.85.102 <none> 80/TCP 22mkube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 26mkubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.15.138.130 <none> 8000/TCP 3m32s[root@master ~]#
4、创建配置文件,并执行后查看效果
[root@master ~]# vim dashboard-svc.yaml #编辑配置文件[root@master ~]# kubectl apply -f dashboard-svc.yaml #执行创建Podservice/kubernetes-dashboard created[root@master ~]# kubectl get svc --all-namespaces #产科service的所有命名空间NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdefault kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 29mdefault php-apache ClusterIP 10.13.85.102 <none> 80/TCP 24mkube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 29mkubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.15.138.130 <none> 8000/TCP 6m19skubernetes-dashboard kubernetes-dashboard NodePort 10.2.126.80 <none> 443:31980/TCP 11s[root@master ~]# cat dashboard-svc.yaml #配置文件内容kind: ServiceapiVersion: v1metadata: labels: k8s-app: kubernetes-dashboard name: kubernetes-dashboard namespace: kubernetes-dashboardspec: type: NodePort ports: - port: 443 targetPort: 8443 selector: k8s-app: kubernetes-dashboard[root@master ~]#
5、想要访问dashboard服务,就要有访问权限,创建kubernetes-dashboard管理员角色
[root@master ~]# vim dashboard-svc-account.yaml #创建dashboard管理员权限文件[root@master ~]# [root@master ~]# kubectl apply -f dashboard-svc-account.yaml #执行文件serviceaccount/dashboard-admin createdclusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created[root@master ~]# cat dashboard-svc-account.yaml apiVersion: v1kind: ServiceAccountmetadata: name: dashboard-admin namespace: kube-system---kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1 #需要修改的地方metadata: name: dashboard-adminsubjects: - kind: ServiceAccount name: dashboard-admin namespace: kube-systemroleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io[root@master ~]#
6、获取 token
#获取token文件名[root@master ~]# kubectl get secret -n kube-system|grep admin|awk '{print $1}'dashboard-admin-token-86qqf[root@master ~]# #获取token文件密码[root@master ~]# kubectl describe secret dashboard-admin-token-86qqf -n kube-system|awk '/^token/ {print $2}'eyJhbGciOiJSUzI1NiIsImtpZCI6IjIxUml2eEg1c3lJS2JSX0RfbnJGMWhVTFNkMlhUd0lyTmJJTkpMeEgwU3cifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tODZxcWYiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZTc3ZjNiNTgtNTQzOS00ODdmLWIyMTItNzg3NzAyZWY2ODZmIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.ckTU-FNo_U-aAoD9_EQij8uhcenJs0erurI2vrAfvc_44cGBaHII1ES3OM2Ufx1d_Pb48uQQzs2HmiyNkiFo3FOmGKpcBg16ndhXww78FB54hyd7kgL-sDN5Y6WDOaqn9MN7XWONBFS_ygmdJIaaGOJWQzoKeJ17_44YB1ddhUpSgbgH4TdIDZpnc3GdGkn2S8i7PkxoWEyIFGE7sOayF5lMXnoSDSoPmm2RB-Bukqq17JN1ZaAql92KeS4k3Ca9nzlNy7iRfLyxSFifPM3mUIl9tWPbR83OQKBHjkafggYmhtlm4vkSxXgltJ3cE8yQNEzfHVePLx0WPLR2YEAkxQ[root@master ~]#
7、访问dashboard
#查看端口为31980[root@master ~]# kubectl get svc --all-namespacesNAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEdefault kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 39mdefault php-apache ClusterIP 10.13.85.102 <none> 80/TCP 34mkube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 39mkubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.15.138.130 <none> 8000/TCP 16mkubernetes-dashboard kubernetes-dashboard NodePort 10.2.126.80 <none> 443:31980/TCP 10m[root@master ~]# [root@master pod]# kubectl get pod -o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESmy-nginx-575db987b-49jnv 1/1 Running 0 24m 10.244.1.5 node1 <none> <none>my-nginx-575db987b-rmnvh 1/1 Running 0 24m 10.244.3.5 node3 <none> <none>my-nginx-575db987b-w2xvf 1/1 Running 0 24m 10.244.2.5 node2 <none> <none>[root@master pod]# #访问网站(前提是你的node节点服务器上必须纯在运行的Pod服务,如nginx、mysql、redis等,否则无法访问该网站)https://192.168.2.149:31980/#/login
8、输入上面获得的token,然后登录
创建dashboard成功!
本文链接:https://www.kjpai.cn/news/2024-03-31/151777.html,文章来源:网络cs,作者:康由,版权归作者所有,如需转载请注明来源和作者,否则将追究法律责任!
下一篇:返回列表