k8s集群管理工具

當集群數量比較多的時候,管理起來比較麻煩。如果是使用云廠商的集群,可以在控制臺界面進行管理,但如果是自己搭建的集群,想要在命令行界面管理的話,可以使用kubecm和k9s工具。

kubecm

kubecm可以用來將所有kubeconfig匯集到一起,并方便地進行上下文切換。

安裝

可以參考release下載二進制安裝。

常用命令

  • kubecm add --context-name <name> -f <your-kubeconfig> 將kubeconfig添加到~/.kube/config文件中。

  • kubecm list 查看所有的kubeconfig,效果如下。

    image.png

  • kubecm switch <context-name> 切換到指定的context。

  • kubecm delete <context-name> 刪除指定的context。

  • kubecm merge config1.yam config2.yaml 合并多個kubeconfig到~/.kube/config中。
    其他命令參考:https://kubecm.cloud/en-us/README

k9s

安裝

  1. 可以選擇命令行安裝,也可以直接從release下載編譯好的二進制。
  2. 配置文件:執行k9s info,可以看到配置文件路徑,通常位于以下路徑。
    image.png
  3. 編輯配置文件(如果配置文件不存在或內容為空),參考
k9s:
  # Represents ui poll intervals. Default 2secs
  refreshRate: 2
  # Number of retries once the connection to the api-server is lost. Default 15.
  maxConnRetry: 5
  # Enable mouse support. Default false
  enableMouse: true
  # Set to true to hide K9s header. Default false
  headless: false
  # Set to true to hide K9s crumbs. Default false
  crumbsless: false
  # Indicates whether modification commands like delete/kill/edit are disabled. Default is false
  readOnly: false
  # Toggles whether k9s should exit when CTRL-C is pressed. When set to true, you will need to exist k9s via the :quit command. Default is false.
  noExitOnCtrlC: false
  # Toggles icons display as not all terminal support these chars.
  noIcons: false
  # Toggles whether k9s should check for the latest revision from the Github repository releases. Default is false.
  skipLatestRevCheck: false
  # Logs configuration
  logger:
    # Defines the number of lines to return. Default 100
    tail: 200
    # Defines the total number of log lines to allow in the view. Default 1000
    buffer: 500
    # Represents how far to go back in the log timeline in seconds. Setting to -1 will show all available logs. Default is 5min.
    sinceSeconds: 300
    # Go full screen while displaying logs. Default false
    fullScreenLogs: false
    # Toggles log line wrap. Default false
    textWrap: false
    # Toggles log line timestamp info. Default false
    showTime: false
  # Indicates the current kube context. Defaults to current context
  currentContext: minikube
  # Indicates the current kube cluster. Defaults to current context cluster
  currentCluster: minikube
  # Persists per cluster preferences for favorite namespaces and view.
  clusters:
    coolio:
      namespace:
        active: coolio
        # With this set, the favorites list won't be updated as you switch namespaces
        lockFavorites: false
        favorites:
        - cassandra
        - default
      view:
        active: po
      featureGates:
        # Toggles NodeShell support. Allow K9s to shell into nodes if needed. Default false.
        nodeShell: false
      # Provide shell pod customization of feature gate is enabled
      shellPod:
        # The shell pod image to use.
        image: killerAdmin
        # The namespace to launch to shell pod into.
        namespace: fred
        # The resource limit to set on the shell pod.
        limits:
          cpu: 100m
          memory: 100Mi
      # The IP Address to use when launching a port-forward.
      portForwardAddress: 1.2.3.4
    kind:
      namespace:
        active: all
        favorites:
        - all
        - kube-system
        - default
      view:
        active: dp
  # The path to screen dump. Default: '%temp_dir%/k9s-screens-%username%' (k9s info)
  screenDumpDir: /tmp

用法

直接命令行輸入k9s,會自動用~/.kube/config中當前context的集群。
:用于切換資源。如輸入:namespace就會切換到namespace視圖,輸入:deploy會進入deploy視圖,輸入:context可以切換到不同的集群。
/用于查找資源。如namespace視圖輸入/namespace1用于查找名為namespace1的命名空間,其他資源同理。
esc返回上一個視圖
:q!退出k9s。
j/k上下移動。
空格選擇該資源。
enter進入該資源。如在命名空間界面按空格選擇一個命名空間,然后按enter查看該命名空間下的pod。
tab自動補全。非常強大,使用起來很方便。
其他命令用法可以參考界面提示。如l可以查看pod的日志,d可以describe資源。

image.png

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容