V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
huangmingyou
V2EX  ›  Kubernetes

分享一个 vim 管理 k8s 的方法

  •  
  •   huangmingyou · 2021-07-22 11:46:18 +08:00 · 3362 次点击
    这是一个创建于 1002 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在.vimrc 里面添加配置
    map <F6> :.w !/usr/local/bin/klog


    klog 脚本内容如下
    #!/bin/bash
    read a

    kubectl logs -f --tail 10 $a


    使用:

    用 vim 打开一个包含 pod 名字的文件,跳转到某一条 pod 所在的行,按 f6 就可以直接查看 pod 日志。
    14 条回复    2021-07-22 22:40:11 +08:00
    css3
        1
    css3  
       2021-07-22 12:13:37 +08:00 via iPhone
    挺有意思,有空尝试一下
    chendy
        2
    chendy  
       2021-07-22 12:30:53 +08:00
    这个操作是什么时候用的呢,为啥不直接做个脚本或者 alias ?
    wellsc
        3
    wellsc  
       2021-07-22 12:31:29 +08:00 via iPhone
    牛逼
    huangmingyou
        4
    huangmingyou  
    OP
       2021-07-22 13:03:51 +08:00
    @chendy 连续看多个 pod 的时候,简化操作步骤。方便在 vim 里面搜索 pod
    etby
        5
    etby  
       2021-07-22 13:49:31 +08:00
    我选择 K9S
    ck65
        6
    ck65  
       2021-07-22 13:53:05 +08:00
    感谢分享,我继续使用 K9s
    rainfd
        7
    rainfd  
       2021-07-22 14:07:10 +08:00
    K9s+1
    kennylam777
        8
    kennylam777  
       2021-07-22 15:39:12 +08:00
    k9s + 10086
    li24361
        9
    li24361  
       2021-07-22 16:58:07 +08:00
    感谢楼上几位,第一次知道 K9s
    lululau
        10
    lululau  
       2021-07-22 17:03:10 +08:00
    一个 k9s plugin,支持在一个新打开的 TMUX window / iTerm2 Tab 中打开日志,前提是容器内有 lnav

    lnav:
    # Define a mnemonic to invoke the plugin
    shortCut: Shift-L
    # What will be shown on the K9s menu
    description: Lnav the latest log file in /data/logs/*/
    # Collections of views that support this shortcut. (You can use `all`)
    scopes:
    - po
    # The command to run upon invocation. Can use Krew plugins here too!
    command: sh
    # Whether or not to run the command in background mode
    background: false
    # Defines the command arguments
    args:
    - -c
    - |
    if [ -n "${TMUX}" ]; then
    tmux new-window -n 'lnav ($NAME)' "kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -c \"/usr/bin/lnav /data/logs/*/\\\$(ls -t /data/logs/*/ | grep -P '\\d{4}-\\d{2}-\\d{2}.*\\.(log|gz)' | head -1)\""
    else
    osascript -e '
    tell app "iTerm2"
    tell current window
    create tab with default profile command "/usr/local/bin/kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -c '"'"'/usr/bin/lnav /data/logs/*/$(ls -t /data/logs/*/ | grep -P \"\\d{4}-\\d{2}-\\d{2}.*\\.(log|gz)\" | head -1)'"'"'"
    end
    end'
    fi
    Pythondr
        11
    Pythondr  
       2021-07-22 17:38:53 +08:00   ❤️ 1
    zzzmj
        12
    zzzmj  
       2021-07-22 18:44:59 +08:00
    k9s+1,如果只是日志的话,可以用 stern.
    Ansen
        13
    Ansen  
       2021-07-22 20:48:45 +08:00
    我选择用 lens
    morty0
        14
    morty0  
       2021-07-22 22:40:11 +08:00
    我选择 ELK
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   911 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 20:35 · PVG 04:35 · LAX 13:35 · JFK 16:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.