Skip to content

Instantly share code, notes, and snippets.

@tyokyo320
Forked from embano1/examples.md
Created May 16, 2023 12:14
Show Gist options
  • Save tyokyo320/fc1cce44cbe34565452fa9a50a91d0ac to your computer and use it in GitHub Desktop.
Save tyokyo320/fc1cce44cbe34565452fa9a50a91d0ac to your computer and use it in GitHub Desktop.
kubectl JSON and sort examples

get events sorted by counts and only some fields we're interested in

$ kubectl -n pubsub get ev --sort-by count -o custom-columns='NAME:.metadata.name,KIND:involvedObject.kind,MSG:.message,FIRST:firstTimestamp,COUNT:.count'

using go templating

$ kubectl get events  --sort-by='.metadata.creationTimestamp'  -o 'go-template={{range .items}}{{.involvedObject.name}}{{"\t"}}{{.involvedObject.kind}}{{"\t"}}{{.message}}{{"\t"}}{{.reason}}{{"\t"}}{{.type}}{{"\t"}}{{.firstTimestamp}}{{"\n"}}{{end}}'
@tyokyo320
Copy link
Author

# namespace: kube-system
$ kubectl -n kube-system get events --sort-by count -o custom-columns='NAME:.metadata.name,KIND:involvedObject.kind,MSG:.message,FIRST:firstTimestamp,COUNT:.count'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment