Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kubectl get events only for a pod

When I run kubectl -n abc-namespace describe pod my-pod-zl6m6, I get a lot of information about the pod along with the Events in the end.

Is there a way to output just the Events of the pod either using kubectl describe or kubectl get commands?

like image 953
Rakesh N Avatar asked Aug 20 '18 12:08

Rakesh N


People also ask

How do you see events in a pod?

Using kubectl, you may have seen them when describing a pod or other resource that is not working correctly. For the most part, events are easy to see when you are trying to debug issues for a specific resource. Using kubectl describe pod <podname> for example will show events at the end of the output for the pod.

How do you get logs of a pod in Kubernetes?

If you run kubectl logs pod_name , a list of containers in the pod is displayed. You can use one of the container names to get the logs for that specific container.

How do you check event logs in Kubernetes pod?

Access event logs Developers, application and infrastructure operators can use the kubectl describe command against specific resources, or use the more generic kubectl get event command to list events for a specific resource, or for the entire cluster.


2 Answers

You can use the event command of kubectl.

To filter for a specific pod you can use a field-selector:

kubectl get event --namespace abc-namespace --field-selector involvedObject.name=my-pod-zl6m6 

To see what fields are possible you can use kubectl describe on any event.

like image 56
mszalbach Avatar answered Sep 17 '22 18:09

mszalbach


This answer gives context to @mszalbach's's answer.

  1. You should first understand the data structure of the events object. You can use kubectl get events --output json to check the data structure.

    $ kubectl get events --output json {     "apiVersion": "v1",     "items": [         {             "apiVersion": "v1",             "count": 259,             "eventTime": null,             "firstTimestamp": "2020-04-15T12:00:46Z",             "involvedObject": {                 <------ **this**                 "apiVersion": "v1",                 "fieldPath": "spec.containers{liveness}",                 "kind": "Pod",                                "name": "liveness-exec",        <------ **this**                 "namespace": "default",                 "resourceVersion": "725991",                 "uid": "3f497636-e601-48bc-aec8-72b3edec3d95"             },             ... 
  2. Then, you can do something like this

    kubectl get events --field-selector involvedObject.name=[...]`.  
like image 23
kyakya Avatar answered Sep 21 '22 18:09

kyakya