Kubernetes events are automatically created when resources have state changes, errors or other messages that should be broadcasted to the system.
These events (logs) are very helpful for debugging issues in a Kubernetes cluster.
Unfortunately, a kubectl get events
command, by default, returns an unsorted list of the events that is not easy to search through.
This note shows how to get the events using the kubectl
command and sort them by time.
Cool Tip: Get events from a specific Node using the kubectl
command! Read more →
Kubectl: Get Events & Sort By Time
Run one of the commands below, to get events (logs) in a Kubernetes cluster, depending on a context:
$ kubectl get events $ kubectl get events -n <namespaceName> $ kubectl get events --all-namespaces
To set the events output format to a “wide” and to watch (tail) the events in a real time, add the -o wide
and -w
options correspondingly:
$ kubectl get events -o wide
To watch (tail) the events in a real time:
$ kubectl get events -w
To sort the events by time, execute one of the commands below:
$ kubectl get events --sort-by='.lastTimestamp'
- or -
$ kubectl get events --sort-by=.metadata.creationTimestamp
Cool Tip: How to increase a verbosity of the kubectl
command! Read more →
Nope, this won’t work:
“warning: –watch or –watch-only requested, –sort-by will be ignored”
You are right. I’ve removed that example. Thanks.