Sub topic 4
Reading events to find the cause
This chapter assumes you can run kubectl get and kubectl describe, and that you know the difference between a pod phase and a container state from the earlier chapters. Here you learn to read the events Kubernetes records about a pod. Events usually name the cause of a failure directly.
What events are
An event is a short record that a component, such as the scheduler or the kubelet, writes when something happens to an object. Each event has a type (Normal or Warning), a reason, a message, and a count of how often it repeated.
Events are not logs from your application. They describe what the cluster did to the pod: scheduling it, pulling its image, starting it, killing it. By default the API server keeps events for about one hour, so look soon after a failure.
Two ways to see them
kubectl describe pod prints events at the bottom, under Events:. The second command lists events for one pod and sorts them by time.
kubectl describe pod web | grep -A 10 'Events:'
kubectl get events --field-selector involvedObject.name=web --sort-by=.lastTimestampUse describe for a quick look. Use get events when many objects are involved. Add -A to search all namespaces. Events are namespaced, so a missing result often means you are in the wrong namespace.
Reading one event
Here is a typical Warning from a pod that cannot be placed on a node:
Type Reason Age From Message
Warning FailedScheduling 12s default-scheduler 0/3 nodes are available: 3 Insufficient memory.Read it in this order:
- Reason is the category. It is the best thing to search for.
- From is the component that reported it. It tells you which stage failed.
- Message holds the specifics, such as which resource, taint, or image name.
Common reasons and where they point
| Reason | From | Usually means |
|---|---|---|
| `FailedScheduling` | default-scheduler | No node fits the pod: resources, taints, selectors, or volumes |
| `Failed`, `ErrImagePull` | kubelet | Image name, tag, or registry credentials are wrong |
| `BackOff` | kubelet | The kubelet is waiting before retrying a pull or restart |
| `Unhealthy` | kubelet | A liveness, readiness, or startup probe failed |
| `Killing` | kubelet | The container is being stopped, for example after probe failures |
The From column narrows the search. A scheduler event means the pod never reached a node. A kubelet event means it did, and something failed on that node.
Reading the timeline
Sort by time and read from the top. The first Warning is usually the cause. Later events are often consequences. For example, BackOff follows Failed, and the retry delay is a symptom of the earlier pull error.
Exercise
A pod's describe output shows an empty Events section, but the pod is in CrashLoopBackOff. Give two likely explanations and one next step.
Show answer
Events expire after about an hour, or you are looking in the wrong namespace. Next step: run kubectl logs web --previous and check the terminated state's exit code and reason.