目录
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 ~]# ls
anaconda-ks.cfg recommended.yaml
[root@master ~]#
1.2、创建 pod
[root@master ~]# 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
[root@master ~]#
2、查看dashboard是否成功创建
[root@master ~]# kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default php-apache-779bc4fcc9-4ct7p 1/1 Running 0 20m
kube-flannel kube-flannel-ds-6swk8 1/1 Running 0 22m
kube-flannel kube-flannel-ds-dvpv4 1/1 Running 0 22m
kube-flannel kube-flannel-ds-kl2nd 1/1 Running 0 22m
kube-flannel kube-flannel-ds-t5lxb 1/1 Running 0 22m
kube-system coredns-6d8c4cb4d-h5n8s 1/1 Running 0 24m
kube-system coredns-6d8c4cb4d-vttkv 1/1 Running 0 24m
kube-system etcd-master 1/1 Running 64 24m
kube-system kube-apiserver-master 1/1 Running 70 24m
kube-system kube-controller-manager-master 1/1 Running 28 24m
kube-system kube-proxy-6b6x6 1/1 Running 0 24m
kube-system kube-proxy-bdlf2 1/1 Running 0 24m
kube-system kube-proxy-m88cm 1/1 Running 0 24m
kube-system kube-proxy-ws5mn 1/1 Running 0 24m
kube-system kube-scheduler-master 1/1 Running 24 24m
kubernetes-dashboard dashboard-metrics-scraper-6f669b9c9b-8mssp 1/1 Running 0 86s
kubernetes-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-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 26m
default php-apache ClusterIP 10.13.85.102 <none> 80/TCP 21m
kube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 26m
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.15.138.130 <none> 8000/TCP 3m
kubernetes-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-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 26m
default php-apache ClusterIP 10.13.85.102 <none> 80/TCP 22m
kube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 26m
kubernetes-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 #执行创建Pod
service/kubernetes-dashboard created
[root@master ~]# kubectl get svc --all-namespaces #产科service的所有命名空间
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 29m
default php-apache ClusterIP 10.13.85.102 <none> 80/TCP 24m
kube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 29m
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.15.138.130 <none> 8000/TCP 6m19s
kubernetes-dashboard kubernetes-dashboard NodePort 10.2.126.80 <none> 443:31980/TCP 11s
[root@master ~]# cat dashboard-svc.yaml #配置文件内容
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:
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 created
clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created
[root@master ~]# cat dashboard-svc-account.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: dashboard-admin
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1 #需要修改的地方
metadata:
name: dashboard-admin
subjects:
- kind: ServiceAccount
name: dashboard-admin
namespace: kube-system
roleRef:
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-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 39m
default php-apache ClusterIP 10.13.85.102 <none> 80/TCP 34m
kube-system kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 39m
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.15.138.130 <none> 8000/TCP 16m
kubernetes-dashboard kubernetes-dashboard NodePort 10.2.126.80 <none> 443:31980/TCP 10m
[root@master ~]#
[root@master pod]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-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成功!