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
- kubectl describe — Events in Resource
- Audit Logs — API Auditing
- Quick Reference — Most Used Commands
- Pro Tips
kubectl get events — List Events
Shows cluster events (useful for troubleshooting).
Basic Usage
$ 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
| Flag | Purpose |
|---|---|
-A | All namespaces |
-n | Specific namespace |
--sort-by | Sort by time, type, reason |
-w | Watch events in real-time |
Examples
List events with sorting (newest first):
$ kubectl get events --sort-by='.lastTimestamp' | tail -10Watch events in real-time:
$ kubectl get events -wList events for a specific pod:
$ kubectl get events --field-selector involvedObject.name=my-podList only warnings:
$ kubectl get events --field-selector type=WarningList events with custom output:
$ kubectl get events -o widekubectl describe — Events in Resource
Events are also shown when describing a resource.
$ 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 containerAudit 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:
$ tail -f /var/log/kubernetes/audit.logIf audit logs are sent to CloudWatch/Elasticsearch:
$ kubectl logs -n kube-system <audit-log-pod>Common Audit Fields
| Field | Description |
|---|---|
user | Who made the request |
verb | Action (get, list, create, update, delete) |
objectRef | Resource being accessed |
responseStatus | Success or failure |
requestReceivedTimestamp | When request was received |
sourceIPs | Source IP of request |
Useful jq Queries for JSON Audit Logs
# 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
| Task | Command |
|---|---|
| List all events | kubectl get events |
| List events in namespace | kubectl get events -n production |
| List events in all namespaces | kubectl get events -A |
| Sort events by time | kubectl get events --sort-by='.lastTimestamp' |
| List events for a pod | kubectl get events --field-selector involvedObject.name=my-pod |
| List warning events only | kubectl get events --field-selector type=Warning |
| Watch events | kubectl get events -w |
| Describe resource (includes events) | kubectl describe pod my-pod |
Pro Tips
-
Events are ephemeral — they expire after a certain time (usually 1 hour by default).
-
Use
--field-selectorto filter events:bashkubectl get events --field-selector involvedObject.kind=Pod kubectl get events --field-selector involvedObject.namespace=production -
Check events for all namespaces:
kubectl get events -A --sort-by='.lastTimestamp' -
Events are also in
describeoutput — more readable for specific resources. -
Watch events during troubleshooting:
kubectl get events -w -A -
Audit logging requires enabling in API server:
--audit-policy-file=/etc/kubernetes/audit-policy.yaml -
Event storage options: etcd (default), separate database, or streaming to external systems.
-
Omit event noise: use
jqorgrepto filter out normal events.