Sub topic 2
Reading resources with kubectl get and describe
This chapter assumes you can run basic kubectl commands, know what Pods, Deployments, and Nodes are, and can read YAML. You need access to a cluster, such as kind or minikube.
Every Kubernetes object has a spec (what you asked for) and a status (what the cluster observed). Two commands show you both: kubectl get for a quick summary, and kubectl describe for detail and events.
Start with kubectl get
kubectl get prints one line per object. The columns come from the server and differ by resource type. For Pods, the default columns are NAME, READY, STATUS, RESTARTS, and AGE.
Add -o wide to get more columns, such as the Pod IP and the node it runs on.
kubectl get pod web-0 -o wide
kubectl describe pod web-0The READY column shows containers ready out of containers total, for example 1/2. The STATUS column is a display string. It is not the same as the Pod's phase field. kubectl computes it from several fields, so you may see values like CrashLoopBackOff or Init:0/1 that are not phases. Later chapters cover phase and container states in detail.
Go deeper with kubectl describe
kubectl describe gathers information from several places and formats it for people. For a Pod, the output includes:
- Metadata such as labels, annotations, and the owning controller.
- The node and IP address.
- Each container's image, state, last state, restart count, and readiness.
- Pod conditions.
- Volumes.
- An Events section at the bottom.
The Events section is the reason to reach for describe first. It lists recent events recorded about this object, such as scheduling decisions, image pulls, and probe failures. These events often name the cause of a problem directly.
Read the raw status with -o yaml
describe is formatted for readability and its layout can change between kubectl versions. When you need the exact fields, use -o yaml. The status block shows what the cluster has observed.
status:
phase: Running
conditions:
- type: Ready
status: "False"
reason: ContainersNotReady
containerStatuses:
- name: app
ready: false
restartCount: 5
state:
waiting:
reason: CrashLoopBackOff
lastState:
terminated:
reason: Error
exitCode: 1This excerpt shows why you should not trust one field alone. The phase is Running, yet the container is waiting in CrashLoopBackOff after exiting with an error, and the Pod is not Ready. The lastState.terminated block tells you how the previous run ended.
Choosing between the two
| Need | Command |
|---|---|
| Quick health check of many objects | `kubectl get` |
| Extra columns such as node and IP | `kubectl get -o wide` |
| Events and a readable summary of one object | `kubectl describe` |
| Exact field names and values | `kubectl get -o yaml` |
Common mistakes
- Forgetting the namespace. Both commands default to the current namespace. Use
-n <namespace>, or-Awithgetto list across all namespaces. - Reading only the STATUS column. It is a summary. Check conditions and container states when it looks fine but the app is not working.
- Describing the wrong object. A Deployment's events rarely explain a Pod's failure. Describe the Pod, and if needed its ReplicaSet.
- Missing old events. Events expire after a short time, so an empty Events section does not mean nothing happened. A later chapter covers this.
Exercise
A Pod shows STATUS Running in kubectl get, but users report the app is down. Which command and which parts of its output should you check next, and why?
Show answer
Run kubectl describe pod <name> (or kubectl get pod <name> -o yaml). Check the container states and restart count, the Ready condition, and the Events section. The STATUS column is a summary, and a container can be restarting or not ready while the Pod phase is still Running.