Skip to content

Instantly share code, notes, and snippets.

@embano1
Last active May 16, 2023 12:14
Show Gist options
  • Save embano1/f4844fc04a5ec6444d947dd88681445e to your computer and use it in GitHub Desktop.
Save embano1/f4844fc04a5ec6444d947dd88681445e 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}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment