get, describe, logs: finding out what happened
The situation
From here on, most lessons start with something broken and no explanation. Three commands do most of the finding out:
| Command | Answers |
|---|---|
kubectl get <kind> | What exists, and is it healthy? One line per object. |
kubectl describe <kind> <name> | Its full story: settings, conditions, and the Events at the bottom (scheduled, pulled, started, killed, failed). |
kubectl logs <pod> | What the program itself printed to stdout and stderr. |
Add -o wide to get for extra columns such as the node, and -o yaml for
everything. kubectl logs deploy/<name> picks one of a Deployment's pods for
you.
A greeter app is running in kubelings. When it starts, it prints a random
secret word.
Your task
Find two facts and record them in a ConfigMap named findings:
word: the secret wordgreeterprinted in its logsnode: the name of the nodegreeter's pod is running on
kubectl -n kubelings get pods -o wide
kubectl -n kubelings describe pod -l app=greeter
kubectl -n kubelings logs deploy/greeter
Then store what you found. The check reads it from here:
kubectl -n kubelings create configmap findings \
--from-literal=word=<the-word> \
--from-literal=node=<the-node>
Hint
The NODE column of get pods -o wide and the Node: line of describe both
give the node.
Got one wrong? A ConfigMap is replaced, not edited, the quick way:
kubectl -n kubelings delete configmap findings
kubectl -n kubelings create configmap findings --from-literal=word=... --from-literal=node=...
Solution
WORD=$(kubectl -n kubelings logs deploy/greeter | sed -n 's/^the secret word is //p')
NODE=$(kubectl -n kubelings get pods -l app=greeter -o jsonpath='{.items[0].spec.nodeName}')
kubectl -n kubelings create configmap findings --from-literal=word="$WORD" --from-literal=node="$NODE"
Which command, when
- Pod not Running?
describefirst. The Events say whether it is waiting for a node, failing to pull its image, or being killed. - Pod Running but misbehaving, or restarting?
logs. Add--previousto read the logs of the container that just crashed. - Not sure where to look?
kubectl get events -n <ns> --sort-by=.lastTimestampshows recent events for the whole namespace.
Next
That is the toolkit. Module 1 — Foundations starts with a pod stuck in
CrashLoopBackOff and expects you to use exactly these three commands to find
out why.
- Previous lesson
- Deployments: let Kubernetes keep your pods alive
- Next lesson
- CrashLoopBackOff: read the logs before you guess