Kubernetes

Kubectl Get Events To Sort By Time

While other resources have changes, errors, or other notifications that should be broadcasted to the system, Kubernetes events are generated automatically. There is not so much documentation on events, but they are a great help when troubleshooting problems in your Kubernetes cluster. When compared to many other Kubernetes objects, events have a lot of activity. Events have a one-hour life period by default, and a distinct etcd cluster is advised for scalability. Events on their own, when combined with the inability to filter or aggregate, may not be particularly valuable unless they are transferred to external systems. Kubernetes events are entities that inform you what’s going on inside a cluster, like the scheduler’s decisions and why some pods were ejected from a node. The API Server allows all key components and extensions (operators) to generate events. When something is not operating as planned, the first area to check at is events and network operations. If the failure is the outcome of earlier events or when performing post-mortem analysis, keeping them for a longer duration is critical. Kubernetes generates events every time any of the resources it manages changes. The entity that initiated the event, the kind of event, and the cause are generally included in these events. Now to sort events by time, you have to follow the appended steps described in this tutorial.

Pre-requisites

To sort events by time using kubectl, you have to install the latest version of the Ubuntu Linux system. Currently, we have Ubuntu 20.04 Linux system. Also, make sure to install the minikube cluster in it because it is vital to run Kubernetes services over the Linux system. As we are going to sort events by time using kubectl, make sure to install kubectl as well.

Method to sort events by time Using kubectl

To sort events by time using kubectl, login into the Ubuntu 20.04 system. After that, navigate the command line terminal by searching in either application or using the “Ctrl+Alt+T” shortcut key. Once opened, start the minikube cluster in it by executing the cited below command in the terminal shell.

$ minikube start

The events provide insight into what occurred behind the scenes when a specific item entered a specific state. Getting all events through kubectl get events is another way to see a consolidated list of all events. So try out the below-listed command in the Ubuntu terminal.

$ kubectl get events

As seen above, this provides information on the entity that generated the event and the event’s category, and what prompted it. When trying to check out what’s going on in the system, this data is really useful. These events can also be used to understand long-term system stability and efficiency better.

To get all the events sorted by the creation time from all of the given namespaces, you have to run the appended below command in the terminal window.

$ kubectl get events --sort-by='.metadata.creationTimestamp' -A

You can check out the namespace name, its last seen, type, reason, and object category of the events in the above-attached image.

To sort out the events by the last seen timestamp, execute the following cited command in the shell.

$ kubectl get events --sort-by=’.lastTimestamp’

The output shall be similar to the above-attached snapshot.

Conclusion

In this article, we have gone through the basic concept of events and their usage. Also, we have to check their effectiveness. Along with that, we have listed a method to display all the event details and to sort them by the required time. So, I hope you will easily gather all the information regarding events by following the above-described tutorial.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content