分享两个有利于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

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

1.2、下载yaml文件并运行Dashboard

# 下载yaml文件,如果下载失败那就多下载几次
[root@k8s-master ~]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
​
​
# 修改kubernetes-dashboard的Service类型
[root@k8s-master ~]# vim recommended.yaml 
apiVersion: v1
kind: Namespace
metadata:
  name: kubernetes-dashboard
​
---
​
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
​
---
​
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  type: NodePort    # 增加
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30009   # 增加
  selector:
    k8s-app: kubernetes-dashboard
## 部分内容省略

1.3、部署服务

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

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

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

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

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

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

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部