Skip to content

Filter Kubernetes resources by matching their names

License

Notifications You must be signed in to change notification settings

matoszz/kubectl-grep

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Kubectl Grep

CircleCI GoDoc Go Report Card GitHub release

Filter Kubernetes resources by matching their names

Requirements

  • Kubernetes 1.10.0+
  • Kubectl 1.13.0+

Why we need it?

playing with Kubernetes is my daily job, and I normally search pods by pipe, grep, --label, --field-selector, etc. while hunting abnormal pods, but typing such long commands are quite annoyed.

Before change, we usually filter pods by the following commands,

$ kubectl get pods                           | grep "keyword"
$ kubectl get pods -o wide                   | grep "keyword"
$ kubectl get pods -n "my-ns"                | grep "keyword"
$ kubectl get pods -A                        | grep "keyword"
$ kubectl get pods -l "key=value"            | grep "keyword"
$ kubectl get pods -l "key=value" -n "my-ns" | grep "keyword"
$ kubectl get pods -l "key=value" -A         | grep "keyword"

With this plugin installed, you can filter pod with kubectl grep easily

$ kubectl grep pods "keyword"
$ kubectl grep pods "keyword" -o wide
$ kubectl grep pods "keyword" -n "my-ns"
$ kubectl grep pods "keyword" -A
$ kubectl grep pods "keyword" -l "key=value"
$ kubectl grep pods "keyword" -l "key=value" -n "my-ns"
$ kubectl grep pods "keyword" -l "key=value" -A

Installation

Installation via krew

$ kubectl krew [install|upgrade] grep

Manual Installation

$ export KUBECTL_GREP_VERSION=$(curl -s https://api.github.com/repos/guessi/kubectl-grep/releases/latest | jq -r .tag_name)
$ curl -L -O https://github.com/guessi/kubectl-grep/releases/download/${KUBECTL_GREP_VERSION}/kubectl-grep-$(uname -s)-$(uname -m).tar.gz
$ tar zxvf kubectl-grep-$(uname -s)-$(uname -m).tar.gz
$ mv kubectl-grep /usr/local/bin
$ chmod +x /usr/local/bin/kubectl-grep

Examples

List all pods in default namespace,

$ kubectl grep pods

List all pods in all namespaces,

$ kubectl grep pods -A

List all pods with specific keyword, under specific namespace,

$ kubectl grep pods -n star-lab flash

How to get developer build?

$ go get -u github.com/guessi/kubectl-grep

$ cd ${GOPATH}/src/github.com/guessi/kubectl-grep

$ make all

FAQ

What kind of resource does current release supported?

now it support Nodes, Pods, Deployments, DaemonSets, StatefulSets, ConfigMaps, Secrets, and HPAs

How do I check the tool's version?

$ kubectl grep version

Any plan to support Kubernetes version before 1.10.0?

sorry, it only support Kubernetes 1.10.0+

I'm now running Kubernetes 1.10.0, do I need to upgrade my cluster?

nope, the only requirement is to upgrade your `kubectl` to 1.13.0+

Can I run Kubernetes 1.12.0 with kubectl 1.13.0?

sure, no problem

Reference

License

Apache-2.0

About

Filter Kubernetes resources by matching their names

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 92.7%
  • Makefile 7.3%