A plugin to filter resources Kubernetes resources in YAML.
kubectl grep
will preserve the original YAML structure, including comments, when transformations are not applied.
In addition to filtering out objects, a variety of transformations can be applied:
List
types will automatically be unrolled.Secret
types can be decoded (base64) with--decode/-d
.- Noisy fields can be removed with
--clean/-n
, and status can additional be exluded with--clean-status/-N
. - The list of object names and types can be summarized with
--summary/-s
.
go install github.com/howardjohn/kubectl-grep@latest
A plugin to grep Kubernetes resources.
Usage:
kubectl-grep [flags]
Flags:
-n, --clean Cleanup generate fields
-N, --clean-status Cleanup generate fields, including status
-d, --decode Decode base64 fields in Secrets
-w, --diff Show diff of changes. Use with 'kubectl -ojson -w | kubectl grep -w'
--diff-mode string Format for diffs. Can be [line, inline]. (default "line")
-h, --help help for kubectl-grep
-i, --insensitive-regex Invert regex match
-v, --invert-regex Invert regex match
-r, --regex string Raw regex to match against
-s, --summary Summarize output
kubectl grep
takes matching clauses as arguments.
These follow the form <KIND>/<NAME>.<NAMESPACE>
.
For example, Service/kubernetes.default
.
Partial forms are also accepted:
<KIND>/<NAME>
<KIND>/
<NAME>
Wildcards are allowed as well. For example:
*/name.namespace
- match any kindsService/*.default
- match all services indefault
Service/echo-*.default
- match all services indefault
with a naming starting withecho-
Regex matches can be applied on a per-object basis.
For example, kubectl grep -r security
will search all objects that have the phrase 'security' within them.
-i
can make this case insensitive, and -v
can invert the match.
A stream of events, as output by kubectl get -w -ojson
, can be processed and show the diffs of what is changing.
This can be helpful to debug controllers.
For example:
kubectl get pods -w -ojson | kubectl grep -w
cat some-config.yaml | kubectl grep Service/ | kubectl apply -f -
cat some-config.yaml | kubectl grep Service/helloworld.default
cat some-config.yaml | kubectl grep 'Pod/*/dev' -N
Display all resources that contain the string pertrytimeout
(case-insensitive), but do not contain timeout
.
cat some-config.yaml | kubectl grep -r pertrytimeout -i | kubectl grep -v -r timeout