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:
- Listtypes will automatically be unrolled.
- Secrettypes 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 outputkubectl 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 kinds
- Service/*.default- match all services in- default
- Service/echo-*.default- match all services in- defaultwith a naming starting with- echo-
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 -wcat some-config.yaml | kubectl grep Service/ | kubectl apply -f -cat some-config.yaml | kubectl grep Service/helloworld.defaultcat some-config.yaml | kubectl grep 'Pod/*/dev' -NDisplay 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