当前位置:   article > 正文

[云原生专题-28]:K8S - Kubernetes(K8S)Master集群构建与安装过程详细解读 - Dashboard的安装与访问_nuyostj

nuyostj

作者主页(文火冰糖的硅基工坊):文火冰糖(王文兵)的博客_文火冰糖的硅基工坊_CSDN博客

本文网址: https://blog.csdn.net/HiWangWenBing/article/details/122788745


目录

第1章 Dashboard概述

第2章 安装前置条件

第3章 Dashboard的安装

第4章 Dashboard的访问

4.1 NodePort访问

第5章 Dashboard的使用


第1章 Dashboard概述

K8S Dashboard是官方的一个基于WEB的用户界面,专门用来管理K8S集群,并可展示集群的状态。

K8S集群安装好后默认没有包含Dashboard,我们需要额外创建它。

Dashboard与kubeadm与kubectl一并完成对K8S集群的操作、维护、管理(OAM)

第2章 安装前置条件

K8S Dashboard只适合安装在manager节点。

[云原生专题-24]:K8S - Kubernetes(K8S)Master集群构建与安装过程详细解读 - 初始控制节点的安装_文火冰糖(王文兵)的博客-CSDN博客作者主页(文火冰糖的硅基工坊):文火冰糖(王文兵)的博客_文火冰糖的硅基工坊_CSDN博客本文网址:https://blog.csdn.net/HiWangWenBing/article/details/122759250目录第一步:集群规划1.1 K8S的官方架构1.2 K8S的实验架构1.3 主要步骤1.4K8S集群搭建方式选择1.5 官方参考第二步:搭建云服务器2.1 安装服务器2.2 安装后检查第三步:搭建Docker环境(云平台手工操作)3.1.https://blog.csdn.net/HiWangWenBing/article/details/122759250

第3章 Dashboard的安装

(1)官方一步安装命令

GitHub - kubernetes/dashboard: General-purpose web UI for Kubernetes clusters

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml

问题:无法远程访问远程的配置文件。

因此需要手工下载配置文件到云服务器上。

(2) 用IE打开配置文件

https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml

(3)在本地创建配置文件

  1. $ cd ~
  2. $ touch recommended.yaml
  3. vi recommended.yaml
  4. cat recommended.yaml

(4)手工下载dashboard镜像

$ docker pull kubernetes-dashboard-amd64

(5)Dashboard的安装

  1. [root@k8s-master1 ~]# kubectl apply -f ./recommended.yaml
  2. namespace/kubernetes-dashboard created
  3. serviceaccount/kubernetes-dashboard created
  4. service/kubernetes-dashboard created
  5. secret/kubernetes-dashboard-certs created
  6. secret/kubernetes-dashboard-csrf created
  7. secret/kubernetes-dashboard-key-holder created
  8. configmap/kubernetes-dashboard-settings created
  9. role.rbac.authorization.k8s.io/kubernetes-dashboard created
  10. clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
  11. rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
  12. clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
  13. deployment.apps/kubernetes-dashboard created
  14. service/dashboard-metrics-scraper created
  15. deployment.apps/dashboard-metrics-scraper created

(6)dashboard是以pod服务的形式存在的,参看pod的运行情况

  1. [root@k8s-master1 ~]# kubectl get pods -A
  2. NAMESPACE NAME READY STATUS RESTARTS AGE
  3. kube-system coredns-6d8c4cb4d-6cts2 0/1 ContainerCreating 0 107m
  4. kube-system coredns-6d8c4cb4d-w6x5k 0/1 ContainerCreating 0 107m
  5. kube-system etcd-k8s-master1 1/1 Running 0 108m
  6. kube-system kube-apiserver-k8s-master1 1/1 Running 29 108m
  7. kube-system kube-controller-manager-k8s-master1 1/1 Running 0 108m
  8. kube-system kube-proxy-5wrkx 1/1 Running 0 107m
  9. kube-system kube-scheduler-k8s-master1 1/1 Running 0 108m
  10. kubernetes-dashboard dashboard-metrics-scraper-799d786dbf-88c2w 0/1 ContainerCreating 0 10m
  11. kubernetes-dashboard kubernetes-dashboard-546cbc58cd-292dr 0/1 ContainerCreating 0 10m

服务所在的容器正在创建过程中...........等待,直处于running状态.

  1. [root@k8s-master1 ~]# kubectl get pods -A
  2. NAMESPACE NAME READY STATUS RESTARTS AGE
  3. kube-system calico-kube-controllers-566dc76669-stvkr 1/1 Running 0 104s
  4. kube-system calico-node-fz7s6 1/1 Running 0 104s
  5. kube-system coredns-6d8c4cb4d-6cts2 1/1 Running 0 118m
  6. kube-system coredns-6d8c4cb4d-w6x5k 1/1 Running 0 118m
  7. kube-system etcd-k8s-master1 1/1 Running 1 (9m19s ago) 118m
  8. kube-system kube-apiserver-k8s-master1 1/1 Running 30 (9m9s ago) 118m
  9. kube-system kube-controller-manager-k8s-master1 1/1 Running 1 (9m19s ago) 118m
  10. kube-system kube-proxy-5wrkx 1/1 Running 1 (9m19s ago) 118m
  11. kube-system kube-scheduler-k8s-master1 1/1 Running 1 (9m19s ago) 118m
  12. kubernetes-dashboard dashboard-metrics-scraper-799d786dbf-88c2w 1/1 Running 0 20m
  13. kubernetes-dashboard kubernetes-dashboard-546cbc58cd-292dr 1/1 Running 0 20m

kubernetes-dashboard安装成功!!!!

第4章 Dashboard的访问

根据官方文档,目前访问Dashboard有四种方式:

  • NodePort:通过任意以节点的IP地址和端口号访问。
  • API Server:
  • kubectl proxy
  • Ingress

4.1 NodePort访问

(1)设置NodePort访问方式

kubectl edit svc kubernetes-dashboard -n kubernetes-dashboard

ClusterIP -> NodePort

ClusterIP与NodePort的区别是:

ClusterIP是对外提供一个统一的IP地址,使用统一的集群IP地址访问。

NodePort把每个Node的IP地址都暴露出去,使用Node自身的公网地址访问。

(2)获得NodePort的端口号

  1. [root@k8s-master1 ~]# kubectl get svc -A
  2. NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
  3. default kubernetes ClusterIP 10.1.0.1 <none> 443/TCP 3h14m
  4. kube-system kube-dns ClusterIP 10.1.0.10 <none> 53/UDP,53/TCP,9153/TCP 3h14m
  5. kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.1.253.40 <none> 8000/TCP 96m
  6. kubernetes-dashboard kubernetes-dashboard NodePort 10.1.176.109 <none> 443:30586/TCP 96m

 NodePort    10.1.176.109   <none>        443:30586/TCP            96m

10.1.176.109: 集群内部服务的IP地址

443:集群内部服务的端口号

30586: 对外暴露的端口号

IP: 每个节点的IP地址。

(3)在云服务器上的安全组中开放30586端口号。

(4)为远程Web访问创建账号

  1. cat > /root/dashboard-usr.yaml <<EOF
  2. apiVersion: v1
  3. kind: ServiceAccount
  4. metadata:
  5. labels:
  6. k8s-app: kubernetes-dashboard
  7. addonmanager.kubernetes.io/mode: Reconcile
  8. name: kubernetes-dashboard-admin
  9. namespace: kube-system
  10. ---
  11. apiVersion: rbac.authorization.k8s.io/v1
  12. kind: ClusterRoleBinding
  13. metadata:
  14. name: kubernetes-dashboard-admin
  15. namespace: kube-system
  16. labels:
  17. k8s-app: kubernetes-dashboard
  18. addonmanager.kubernetes.io/mode: Reconcile
  19. roleRef:
  20. apiGroup: rbac.authorization.k8s.io
  21. kind: ClusterRole
  22. name: cluster-admin
  23. subjects:
  24. - kind: ServiceAccount
  25. name: kubernetes-dashboard-admin
  26. namespace: kube-system
  27. EOF
  1. [root@k8s-master1 ~]# kubectl apply -f dashboard-usr.yaml
  2. serviceaccount/kubernetes-dashboard-admin created
  3. clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-admin created

(5)获得远程访问的令牌Token

  1. kubectl get secret -n kube-system |grep dashboard
  2. kubernetes-dashboard-admin-token-8lmm7 kubernetes.io/service-account-token 3 5m19s
  1. [root@k8s-master1 ~]# kubectl -n kube-system describe secrets kubernetes-dashboard-admin-token-8lmm7
  2. Name: kubernetes-dashboard-admin-token-8lmm7
  3. Namespace: kube-system
  4. Labels: <none>
  5. Annotations: kubernetes.io/service-account.name: kubernetes-dashboard-admin
  6. kubernetes.io/service-account.uid: 8ad90e41-949d-4085-9c8c-31ae6e3c8756
  7. Type: kubernetes.io/service-account-token
  8. Data
  9. ====
  10. ca.crt: 1099 bytes
  11. namespace: 11 bytes
  12. token: eyJhbGciOiJSUzI1NiIsImtpZCI6IjdhcHBrRU1TUTJlb0NvM0YtYThIQWRZT01mVTR4X3RfZHhzQnQxODQ0UmsifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbi10b2tlbi04bG1tNyIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjhhZDkwZTQxLTk0OWQtNDA4NS05YzhjLTMxYWU2ZTNjODc1NiIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTprdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiJ9.IyigMqSGjlmAaJyBxnylTWtsxXRPzJ2URrKSsJ9_RroY_0VY6fcMmxL253Tv9uAq_0E4-lZFKgdnMPktfiMaSBQ_g9JfIrjBQUKzCq-Yo5vaycVfFn9K0xPvl4iWjy4O3KNSMGibLXFLHHSoHiHNEht2YlqXw0UNNXrrVaunUWTGxlEWkNFiUB06I-EoGB5MIAzbraYq7Akr_MfRJU4RSP7tieGL-lgk17HfciuSV7bvDjL9ZfnWj5oSTjv35wis5nCxAGPrP1sUbRhvwhDyOFqmHr1sxLFnnsYb4YM0P9dYbUrrU5qywp8iGAuv87e-I7Zwap4iXY9b-nUvt2S8qA

(6)通过集群中的任意端口的公网IP+端口号+令牌访问Dashboard

https://47.99.96.250:30586/

忽略警告,继续访问:

 为了安全起见,dashboard采用HTTPS访问,需要提供一个TokenID访问。

选中全部命名空间:

第5章 Dashboard的使用

至此,我们已经创建了K8的集群,并且创建了图形化的管理界面集群进行管理。

后续就可以进行实际微服务的创建和业务的运营和管理了。


作者主页(文火冰糖的硅基工坊):文火冰糖(王文兵)的博客_文火冰糖的硅基工坊_CSDN博客

本文网址:https://blog.csdn.net/HiWangWenBing/article/details/122788745

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/1020944
推荐阅读
相关标签
  

闽ICP备14008679号