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.DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
Let's Get Started.
DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
How to Get events in Kubernetes Cluster
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
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
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: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:
0 Comments