New batchZero to DevOps starts 29 Nov · limited seatsReserve your seat
Cheat sheetsKubernetesKubernetes
FreeSheet 03 of 16

Events & Auditing

A comprehensive developer cheatsheet covering Kubernetes cluster events and API auditing, featuring essential CLI commands, common flags, and operational workflows for listing, filtering, and watching real-time events with kubectl, inspecting resource event histories, and querying JSON audit logs with jq for cluster troubleshooting and security monitoring.

Table of Contents


kubectl get events — List Events

Shows cluster events (useful for troubleshooting).

Basic Usage

bash
$ kubectl get events
LAST SEEN   TYPE      REASON              OBJECT                MESSAGE
5m          Normal    Scheduled           pod/my-pod            Successfully assigned to node-1
4m          Normal    Pulling             pod/my-pod            Pulling image "nginx"
4m          Normal    Pulled              pod/my-pod            Successfully pulled image
4m          Normal    Created             pod/my-pod            Created container
4m          Normal    Started             pod/my-pod            Started container
3m          Warning   Failed              pod/my-other-pod     Failed to pull image "nginx:latest"

Common Flags

FlagPurpose
-AAll namespaces
-nSpecific namespace
--sort-bySort by time, type, reason
-wWatch events in real-time

Examples

List events with sorting (newest first):

bash
$ kubectl get events --sort-by='.lastTimestamp' | tail -10

Watch events in real-time:

bash
$ kubectl get events -w

List events for a specific pod:

bash
$ kubectl get events --field-selector involvedObject.name=my-pod

List only warnings:

bash
$ kubectl get events --field-selector type=Warning

List events with custom output:

bash
$ kubectl get events -o wide

kubectl describe — Events in Resource

Events are also shown when describing a resource.

bash
$ kubectl describe pod my-pod
...
Events:
  Type     Reason     Age   From               Message
  ----     ------     ----  ----               -------
  Normal   Scheduled  5m    default-scheduler  Successfully assigned default/my-pod to node-1
  Normal   Pulling    5m    kubelet            Pulling image "nginx"
  Normal   Pulled     5m    kubelet            Successfully pulled image "nginx"
  Normal   Created    5m    kubelet            Created container
  Normal   Started    5m    kubelet            Started container

Audit Logs — API Auditing

Audit logs record all API requests made to the cluster (requires audit policy enabled).

View Audit Logs (if configured)

If audit logs are written to a file:

bash
$ tail -f /var/log/kubernetes/audit.log

If audit logs are sent to CloudWatch/Elasticsearch:

bash
$ kubectl logs -n kube-system <audit-log-pod>

Common Audit Fields

FieldDescription
userWho made the request
verbAction (get, list, create, update, delete)
objectRefResource being accessed
responseStatusSuccess or failure
requestReceivedTimestampWhen request was received
sourceIPsSource IP of request

Useful jq Queries for JSON Audit Logs

bash
# Failed requests
$ cat audit.log | jq 'select(.responseStatus.code >= 400)'

# Requests by a specific user
$ cat audit.log | jq 'select(.user.username == "admin")'

# Requests to a specific namespace
$ cat audit.log | jq 'select(.objectRef.namespace == "production")'

# Unauthorized access attempts
$ cat audit.log | jq 'select(.responseStatus.code == 403)'

Quick Reference — Most Used Commands

TaskCommand
List all eventskubectl get events
List events in namespacekubectl get events -n production
List events in all namespaceskubectl get events -A
Sort events by timekubectl get events --sort-by='.lastTimestamp'
List events for a podkubectl get events --field-selector involvedObject.name=my-pod
List warning events onlykubectl get events --field-selector type=Warning
Watch eventskubectl get events -w
Describe resource (includes events)kubectl describe pod my-pod

Pro Tips

  1. Events are ephemeral — they expire after a certain time (usually 1 hour by default).

  2. Use --field-selector to filter events:

    bash
    kubectl get events --field-selector involvedObject.kind=Pod
    kubectl get events --field-selector involvedObject.namespace=production
  3. Check events for all namespaces: kubectl get events -A --sort-by='.lastTimestamp'

  4. Events are also in describe output — more readable for specific resources.

  5. Watch events during troubleshooting: kubectl get events -w -A

  6. Audit logging requires enabling in API server: --audit-policy-file=/etc/kubernetes/audit-policy.yaml

  7. Event storage options: etcd (default), separate database, or streaming to external systems.

  8. Omit event noise: use jq or grep to filter out normal events.


Next in KubernetesIngress Controllers & Networking
Kubernetes cheat sheet: Events & Auditing | InfraThrone DevOps Park