给 kubectl 撸了个插件,支持正则匹配资源名,贼好使!

2021-03-16 20:05:03 +08:00
 FingerLiu

https://github.com/FingerLiu/kubectl-smart

![demo]( https://github.com/FingerLiu/kubectl-smart/raw/main/imgs/kubectl-smart.gif

简介

给 kubectl 支持了正则匹配功能,不管是 namespace 还是资源名,都可以模糊查找。 主要解决了以下两个痛点:

Type less, Live more! 俩字,好使。

安装

curl -LO https://github.com/FingerLiu/kubectl-smart/raw/master/kubectl-smart
chmod +x ./kubectl-smart
sudo mv ./kubectl-smart /usr/local/bin/kubectl-s
kubectl s -h

Examples:
  # if you installed through krew, you should **kubectl smart** to replace **kubectl s**
  # get pod with name contains my in namespace her-namespace
  # (kubectl get pod -n her-namespace-a |grep my)
  kubectl s gp -n her.*a my

  # get log for pod with name my
  # (kubectl logs --tail 100 -f $(kubectl get pods | awk '/my/ {print $1;exit}'))
  kubectl s l my

  # exec into pod
  # kubectl exec -ti my-pod-i3jx bash
  kubectl s e my bash

  # get deploy with name contains my
  # (kubectl get deploy | grep my)
  kubectl s g deploy my
1957 次点击
所在节点    Kubernetes
5 条回复
AnyISalIn
2021-03-16 21:07:56 +08:00
🐮 楼主说的日志场景 stern 可以搞定
mritd
2021-03-17 08:27:11 +08:00
我都是 ohmyzh tab 一手
hwdef
2021-04-14 16:00:26 +08:00
🤪相比之下,正则更难
FingerLiu
2021-04-21 10:37:09 +08:00
@hwdef 正则对小白来说确实比较难入手。但熟练以后效率高是毋庸置疑的
xabcstack
2021-09-28 16:50:37 +08:00
可以看看 Kubectl Pro https://github.com/ywgx/ki 风味更佳

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

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

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

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

© 2021 V2EX