LinuxCommandLibrary

kubectl-events

Stream Kubernetes events

TLDR

Show events in the default namespace

$ kubectl events
copy

Show events in all namespaces
$ kubectl events [[-A|--all-namespaces]]
copy

Watch events in a specific namespace
$ kubectl events [[-w|--watch]] [[-n|--namespace]] [namespace]
copy

Show events for a pod in a specific namespace
$ kubectl events --for [pod]/[pod_name] [[-n|--namespace]] [namespace]
copy

Show events for a resource in a specific namespace
$ kubectl events --for [resource]/[resource_name] [[-n|--namespace]] [namespace]
copy

Show events for type Warning or Normal
$ kubectl events --types Warning,Normal
copy

Output events in YAML format
$ kubectl events [[-o|--output]] yaml
copy

SYNOPSIS

kubectl events [-n <namespace> | --all-namespaces] [-w | --watch] [--for-object <kind>/<name>] [--field-selector <selector>] [--since <duration>] [--sort-by <field>] [-o <format>]

PARAMETERS

-n, --namespace <name>
    Filters events to a specific Kubernetes namespace. If not specified, the current context's namespace is used.

-A, --all-namespaces
    Displays events from all namespaces in the cluster.

-w, --watch
    Continuously streams new events as they occur in real-time. This is analogous to tail -f for events.

--for-object <kind>/<name>
    Filters events to only show those related to a specific Kubernetes object, e.g., pod/my-app-pod or deployment/my-service.

--field-selector <selector>
    Filters events based on their fields, using standard Kubernetes field selectors. Examples: type=Warning, reason=FailedScheduling, involvedObject.kind=Pod.

--since <duration>
    Shows events only since a relative duration ago (e.g., 1h for 1 hour, 5m for 5 minutes). This helps in focusing on recent activity.

--sort-by <field>
    Sorts the displayed events by a specific field, such as lastTimestamp, type, or reason. Default sorting is usually by time.

-o, --output <format>
    Specifies the output format for events, such as json, yaml, wide, or custom-columns, for programmatic parsing or detailed views.

DESCRIPTION

kubectl-events is a popular Kubernetes kubectl plugin designed to provide a more powerful and user-friendly interface for viewing and streaming cluster events than the native kubectl get events command. It addresses common pain points by offering advanced filtering, real-time watching, and customizable output options.

Kubernetes events are crucial for understanding the state and behavior of your cluster, providing insights into resource creation, scheduling decisions, failures, and other important occurrences. kubectl-events simplifies the process of sifting through these events, making it an invaluable tool for cluster administrators, developers, and SREs for debugging, monitoring, and auditing.

While not a built-in kubectl command, it is widely adopted and often installed via plugin managers like krew. Its primary goal is to make event logs more accessible and actionable, enabling quick identification of issues such as failed pod scheduling, image pull errors, or resource allocation problems.

CAVEATS

kubectl-events is a community-contributed kubectl plugin, not part of the official kubectl core distribution. Its availability and exact feature set depend on its installation method (e.g., via krew) and the specific version or implementation you are using.

Users must ensure they have appropriate Role-Based Access Control (RBAC) permissions to list and watch events within the cluster or specified namespaces; otherwise, the command will return authorization errors or an incomplete list of events.

INSTALLATION

The most common way to install kubectl-events is via krew, the Kubernetes plugin manager. If krew is installed, you can simply run:
kubectl krew install events
Alternatively, some versions might be available as standalone binaries or scripts that can be placed in your PATH.

USE CASES

Debugging Pod Failures: Quickly identify reasons for pods failing to schedule, image pull errors, or crash loops by filtering events related to a specific pod.
Monitoring Cluster Health: Watch for Warning events across the cluster to catch potential issues like node disk pressure, out-of-memory events, or network problems.
Auditing Changes: Track resource creation, updates, and deletions by observing relevant events.
Understanding Scheduling: See why a pod was scheduled on a particular node or why it's pending (e.g., due to resource constraints).

HISTORY

The need for an enhanced Kubernetes event viewer arose from the limitations of the default kubectl get events command, which lacked crucial features like continuous watching, robust filtering, and object-specific event querying.

Various community efforts led to the creation of `kubectl-events` plugins, often written in Go or shell scripts, to fill this gap. Its popularity grew significantly with the advent of krew, the Kubernetes plugin manager, which standardized the installation and distribution of such tools, making kubectl-events an indispensable part of many Kubernetes practitioners' toolkits.

SEE ALSO

kubectl(1), kubectl-get(1), kubectl-describe(1), krew(1)

Copied to clipboard