当前位置:   article > 正文

k8s自动补全工具和UI管理界面

k8s自动补全工具和UI管理界面

分享两个有利于K8S的工具

目录

分享两个有利于K8S的工具

一、部署Dashboard(主节点)

介绍

1.1、查看集群状态

1.2、下载yaml文件并运行Dashboard

1.3、部署服务

1.4、创建访问账户、获取token(令牌)

1.5、浏览器访问Dashboard

二、安装kubectl自动补全命令(主节点)

2.1、安装bash-completion工具

2.2、执行bash_completion

2.3、加载kubecel completion


一、部署Dashboard(主节点)

  • 前提部署好一个Kubernetes集群,可以按照我上一章的文章进行部署

介绍

  • Kubernetes Dashboard是一个用于可视化管理和监控Kubernetes集群的Web用户界面。它提供了一种图形化的方式来查看和管理集群中的资源、应用程序和服务。使得用户可以更方便地进行操作和监控

1.1、查看集群状态

  • 确保状态为Ready

  1. [root@k8s-master ~]# kubectl get nodes
  2. NAME         STATUS   ROLES   AGE     VERSION
  3. k8s-master   Ready   master   7m49s   v1.18.0
  4. k8s-node01   Ready   <none>   7m20s   v1.18.0
  5. k8s-node02   Ready   <none>   7m18s   v1.18.0

1.2、下载yaml文件并运行Dashboard

  1. # 下载yaml文件,如果下载失败那就多下载几次
  2. [root@k8s-master ~]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
  3. # 修改kubernetes-dashboard的Service类型
  4. [root@k8s-master ~]# vim recommended.yaml
  5. apiVersion: v1
  6. kind: Namespace
  7. metadata:
  8. name: kubernetes-dashboard
  9. ---
  10. apiVersion: v1
  11. kind: ServiceAccount
  12. metadata:
  13. labels:
  14.   k8s-app: kubernetes-dashboard
  15. name: kubernetes-dashboard
  16. namespace: kubernetes-dashboard
  17. ---
  18. kind: Service
  19. apiVersion: v1
  20. metadata:
  21. labels:
  22.   k8s-app: kubernetes-dashboard
  23. name: kubernetes-dashboard
  24. namespace: kubernetes-dashboard
  25. spec:
  26. type: NodePort # 增加
  27. ports:
  28.    - port: 443
  29.     targetPort: 8443
  30.     nodePort: 30009   # 增加
  31. selector:
  32.   k8s-app: kubernetes-dashboard
  33. ## 部分内容省略

1.3、部署服务

  1. [root@k8s-master ~]# 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
  16. # 查看kubernetes-dashboard命令空间下的资源
  17. [root@k8s-master ~]# kubectl get pod,svc -n kubernetes-dashboard
  18. NAME                                             READY   STATUS             RESTARTS   AGE
  19. pod/dashboard-metrics-scraper-6b4884c9d5-787lm   0/1     ImagePullBackOff   0         41s
  20. pod/kubernetes-dashboard-7b544877d5-6l4tw        0/1     ErrImagePull       0         41s
  21. NAME                               TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
  22. service/dashboard-metrics-scraper   ClusterIP   10.111.21.8     <none>        8000/TCP       41s
  23. service/kubernetes-dashboard       NodePort    10.106.240.109   <none>        443:30009/TCP   41s

1.4、创建访问账户、获取token(令牌)

  • Dashboard支持kuberconfig和Token两种认证方式,这里选择Token认证方式登录

  1. # 创建账号dashboard-admin
  2. [root@k8s-master ~]# kubectl create serviceaccount dashboard-admin -n kubernetes-dashboard
  3. serviceaccount/dashboard-admin created
  4. # 账号授权,绑定cluster-admin角色
  5. [root@k8s-master ~]# kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard-admin
  6. clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin created
  7. # 获取账号token
  8. [root@k8s-master ~]# kubectl describe secrets -n kubernetes-dashboard $(kubectl -n kubernetes-dashboard get secret| awk '/dashboard-admin/ {print $1}')
  9. Name:         dashboard-admin-token-dtb6c
  10. Namespace:   kubernetes-dashboard
  11. Labels:       <none>
  12. Annotations: kubernetes.io/service-account.name: dashboard-admin
  13.             kubernetes.io/service-account.uid: b5885626-bc73-45ba-a7eb-b327fa576d95
  14. Type: kubernetes.io/service-account-token
  15. Data
  16. ====
  17. ca.crt:     1025 bytes
  18. namespace:  20 bytes
  19. ###################################################################
  20. token:     eyJhbGciOiJSUzI1NiIsImtpZCI6IndLcjVNVUljX0dIVzZEUWhrNUR1cTh6Ums0RDQ4VGsxV204eVZrcERwWEUifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tZHRiNmMiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiYjU4ODU2MjYtYmM3My00NWJhLWE3ZWItYjMyN2ZhNTc2ZDk1Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmVybmV0ZXMtZGFzaGJvYXJkOmRhc2hib2FyZC1hZG1pbiJ9.PLD8qEoYxGWE0gz5YmDUcXjYMx6QeCnhsbY8C60BivK5tlm4eqk84pMjsI5BrJs97tVpIb6a9h1lPBrdcR70QfbdFYPW2Qd3Za2kKbK5QModo_ivC1P3RSt0YZDfFLiXGlS44_uQjVEMJZqLDcmNYFPRgEeIicQH3J9FtKvDqdkMXu2kM6XmBqa2G1u8s-JqTVUC_y_OPJUB8W92W1BA6QD7WY7iAkpp78-Jf33qfUdWak8xwdmps5-LSxg3_22hPC3rQ06hD-RP6hl7dE-udHeJRZAMwNFPlZwSi7aNfP8MChBjKP5eW323S0bg820qzGvRZLru9VeHBjxsS_COsA
  21. ###################################################################

1.5、浏览器访问Dashboard

  • 访问地址:https://192.168.93.101:30009

  • 如果访问不到那就是镜像没拉取下来,可以使用魔法或者私信评论免费提供

  • 出现以下的页面代表成功

二、安装kubectl自动补全命令(主节点)

  • 安装之后再使用kubectl命令的时候就可以使用tab键自动补全命令了

2.1、安装bash-completion工具

  • 通常安装在所有master节点上

[root@k8s-master ~]# yum -y install bash-completion

2.2、执行bash_completion

[root@k8s-master ~]# source /usr/share/bash-completion/bash_completion 

2.3、加载kubecel completion

  1. # 在当前bash环境中临时设置命令补全
  2. [root@k8s-master ~]# source <(kubectl completion bash)
  3. # 在当前bash环境中永久设置命令补全
  4. [root@k8s-master ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc
  5. [root@k8s-master ~]# source ~/.bashrc

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

闽ICP备14008679号