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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,457评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,837评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,696评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,183评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,057评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,105评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,520评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,211评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,482评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,574评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,353评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,897评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,489评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,683评论 2 335

推荐阅读更多精彩内容