分享一个 vim 管理 k8s 的方法

2021-07-22 11:46:18 +08:00
 huangmingyou
在.vimrc 里面添加配置
map <F6> :.w !/usr/local/bin/klog


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

kubectl logs -f --tail 10 $a


使用:

用 vim 打开一个包含 pod 名字的文件,跳转到某一条 pod 所在的行,按 f6 就可以直接查看 pod 日志。
3380 次点击
所在节点    Kubernetes
14 条回复
css3
2021-07-22 12:13:37 +08:00
挺有意思,有空尝试一下
chendy
2021-07-22 12:30:53 +08:00
这个操作是什么时候用的呢,为啥不直接做个脚本或者 alias ?
wellsc
2021-07-22 12:31:29 +08:00
牛逼
huangmingyou
2021-07-22 13:03:51 +08:00
@chendy 连续看多个 pod 的时候,简化操作步骤。方便在 vim 里面搜索 pod
etby
2021-07-22 13:49:31 +08:00
我选择 K9S
ck65
2021-07-22 13:53:05 +08:00
感谢分享,我继续使用 K9s
rainfd
2021-07-22 14:07:10 +08:00
K9s+1
kennylam777
2021-07-22 15:39:12 +08:00
k9s + 10086
li24361
2021-07-22 16:58:07 +08:00
感谢楼上几位,第一次知道 K9s
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
2021-07-22 17:38:53 +08:00
zzzmj
2021-07-22 18:44:59 +08:00
k9s+1,如果只是日志的话,可以用 stern.
Ansen
2021-07-22 20:48:45 +08:00
我选择用 lens
morty0
2021-07-22 22:40:11 +08:00
我选择 ELK

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/791026

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX