Kubectl: Get Events & Sort By Time

Kubectl Get Events alt=

This post will show you how to use kubectl command to get realtime events and how to sort it by time. Also we will cover all kubectl events command example to make you understand it better.

Table of Contents

  • How to Get events in Kubernetes Cluster
  • How to Sort events by time in Kubernetes
  • How to Get events for specific resources in Kubernetes
  • How to Filter events by namespace in Kubernetes

If you are interested in learning, Request you to go through the below recommended tutorial.

How to Get events in Kubernetes Cluster

Kubernetes provides an option to get events of resources using the below kubectl get command.

kubectl get events

Above kubectl get events command will show you the events of resources created in kubernetes cluster.

Output will have multiple columns to provide detailed information.

  • First column: the event's timestamp, including the date and time.
  • Second column: the event's type, such as Warning, Normal, or Info.
  • Third column: the Kubernetes object type, such as Pod, Service, or Node.
  • Fourth column: the name of the Kubernetes object.
  • Fifth column: the namespace in which the object exists.
  • Sixth column: the reason for the event.
  • Seventh column: a message describing the event.

How to Sort events by time in Kubernetes

If you want to sort events by time in kubernetes, same kubectl get events can be used with other sort by flag as below.

kubectl get events --sort-by=.metadata.creationTimestamp

Above kubectl get events command will provide the events that will be sorted by timestamps. The recent event will show you at the bottom of the output list. Same command can be used to get events sort by time for other resources like pods.

kubectl get pods --sort-by=.metadata.creationTimestamp

How to Get events for specific resources in Kubernetes

If you want to get events for specific resources in kubernetes like pods, services, we can use the below kubectl describe command.

kubectl describe <object-type> <object-name>

Lets say you want to get events of pod named my-pod, then use below command.

kubectl describe pod my-pod

This command will display detailed information about the pod, including the events that have occurred within the pod.

Above kubectl describe pod command will show you the detailed information about kubernetes pods.

How to Filter events by namespace in Kubernetes

To filter events by namespace, use the following command:
If you want to filter events by namespace in kubernetes, then we have to use the kubectl get events commands like below along with namespace.

kubectl get events --namespace=<namespace>

Let's say we want to filter events for specific namespace called my-namespace, then use the below command:

kubectl get events --namespace=my-namespace

Above kubectl get events command will provide you the complete events of namespace my-namespace.

That's it for this post. Keep practicing and have fun. Leave your comments if any.

Related Searches and Questions asked:

  • Kubectl Dry Run Client and Server Command Examples
  • Kubectl: Get Pod Containers
  • How to Use Kubernetes Control Plane Effectively
  • Troubleshooting Kubernetes Node Disk Pressure

  • Post a Comment

    0 Comments