kubectl get events only for a pod

kubectl get events for pod
kubectl run pod
kubectl delete pod
kubernetes event exporter
kubectl jsonpath
kubectl patch
kubectl delete deployment
kubectl restart 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?

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.

kubectl Cheat Sheet, You can use the event command of kubectl . To filter for a specific pod you can use a field-selector: kubectl get event --namespace  See also: Kubectl Overview and JsonPath Guide. This page is an overview of the kubectl command. kubectl - Cheat Sheet Kubectl Autocomplete BASH source <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first. echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.

You can describe you pod and then grep the number of lines after your Events. You can add a watch if you want to monitor it.

watch "kubectl describe pod my-pod-zl6m6 | grep -A20 Events"

kubectl get events only for a pod, Here are a few quick examples that you will find useful: Warnings only kubectl get events --field-selector type=Warning. No pod events kubectl  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?

Why not display all events and grep for your podname:

kubectl get events --all-namespaces  | grep -i $podname

Types of Kubernetes Events, For example: Run kubectl get events --all-namespaces --watch A load of events will be printed Wait 10 seconds Only new events should be printed kube-​system 60m Normal Pulling pod/node-problem-detector-vmcf2 pulling  What kubectl command can I use to get events sorted by specific fields and print only specific details of events? Ask Question Asked 2 years, 10 months ago

  1. You should understand the data structure of this 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"
            },
            ...
  1. And then do something like kubectl get events --field-selector involvedObject.name=[...].

This answer refers to @mszalbach's.

"kubectl get events --watch" prints old events after some time · Issue , When a user does "kubectl get events" what they probably want is a So if we don't have a purpose built solution events without compaction is only useful How to filter the events of the specified pod kelproject/pykube#117. doing kubectl get events would show up events in mixed order across all resources (tested with pods). This should show events in sorted order by default, since when events from different resources are shown, the user is only interested in the latest events or events in chronological order

If you only want the Event Messages in a short and clear view, @mszalbach answer is the best one.

But if you want all Events with all their elements to be completely displayed you can run:

kubectl describe event [POD_NAME] --namespace [POD's_NAMESPACE]

"kubectl get events" or something else should give a sensible , kubectl get events LAST SEEN TYPE REASON KIND MESSAGE 5m Normal For example, certain node and networking errors that cause pods to restart may not By default, only the past hour of events is preserved by etcd. In addition to kubectl describe pod, another way to get extra information about a pod (beyond what is provided by kubectl get pod) is to pass the -o yaml output format flag to kubectl get pod. This will give you, in YAML format, even more information than kubectl describe pod--essentially all of the information the system has about the Pod

How We Analyze and Visualize Kubernetes Events in Real Time at , Pod started, scheduled, ReplicaSet scaled are informational events, When using kubectl describe to get formatted information on an object, events In the development cluster, as the workloads live only for minutes, there  Assign Memory Resources to Containers and Pods Assign CPU Resources to Containers and Pods Configure GMSA for Windows Pods and containers Configure RunAsUserName for Windows pods and containers Configure Quality of Service for Pods Assign Extended Resources to a Container Configure a Pod to Use a Volume for Storage Configure a Pod to Use a

How to Export Kubernetes Events for Observability and Alerting, Get node version and name only kubectl get pod -o=jsonpath='{.spec.​containers[*].image}' --all- Get events for an individual resource. Here's the context: I need to invoke kubectl delete [podname] via a crontask once a day, and wait until k8s recreates the pod, then log into the container in that pod and run a shell command. So I query the deployment and get something like this:

kubectl commands cheatsheet - FAUN, In some cases, you can access such logs only via the logging service of the Logging operator with a helper pod that accesses to the log files on the host. The easiest way to collect event logs is to simply run kubectl get  Determine the Reason for Pod Failure This page shows how to write and read a Container termination message. Termination messages provide a way for containers to write information about fatal events to a location where it can be easily retrieved and surfaced by tools like dashboards and monitoring software.

Comments
  • This doesn't work for me. I get: Error: unknown flag: --field-selector
  • The official documentation mentioned field-selector since 1.12. I could not find any hint since when this is supported (found some tickets from 2015). So check your kubectl version and the help output to see what is possible with your kubectl version.
  • yeah. i have an older version. :(
  • @toddcscar you can still use more updated version of kubectl with an older server version: for example this will work on kubectl v1.14 against a v1.11 API
  • @toddcscar were you using get or describe? That happened to me because I was trying first with describe and there is no such option in that command
  • While this provides the results, I'd prefer the one with field-selector switch :)
  • Of course, no doubt that is the cleaner solution. Learned about the --field-selector switch just now.
  • you couldnt even grep the podname, because it is not printed with the kubectl get events command