Inspect resources with kubectl
Start with a small, read-only question
A catalog website has two Pods. One is not ready. Before changing anything, find out which object is affected and what its state is. kubectl get retrieves API objects and normally presents a compact table; describe assembles a human-oriented view, often including events. logs retrieves container output. These answer different questions. All commands here are static examples, not executed results. Work through the supplied synthetic fixture first. Optional execution requires an approved disposable cluster, a separately prepared ./lab.kubeconfig with context bytemind-lab, and the book-lab namespace containing the named fixture resources. No kubeconfig or executable image is supplied. Stop if anything differs from the lab inventory.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab config current-contextkubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab get podsThe first command reads local context configuration (the selected context should be bytemind-lab). The second requests the Pod list in book-lab. A context name alone is not proof of the correct cluster; verify its endpoint and identity through your approved lab inventory before contacting it.
NAME READY STATUS RESTARTScatalog-a 1/1 Running 0catalog-b 0/1 Running 3worker-a 0/1 Pending 0Columns are simplified for teaching. Running does not mean Ready. catalog-b warrants investigation; worker-a is a separate scheduling question.
Investigate one named Pod
Use the resource/name form to focus on one object. Events can explain image pulls, scheduling and restart delays, but may be aggregated or expire. Logs contain what a container wrote to its output streams; they are not a complete record of everything the application did. Explicitly select a container with -c, especially when several are present. Limit output and avoid copying sensitive logs into tickets.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab describe pod/catalog-bkubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab logs pod/catalog-b -c app --tail=20kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab logs pod/catalog-b -c app --previous --tail=20In diagnostic.json, previous output reports a missing greeting setting and exit status 1. This suggests checking configuration, not deleting the Pod. Previous logs refer to the prior terminated instance when available; they may be absent. The current log may only show startup.
Discover resources and field definitions
api-resources reports resource types discoverable from the connected server; api-versions lists API group versions, not every resource. explain looks up field documentation from server schemas. Use these before guessing a field name. Discovery may be limited by connectivity or permissions. config manages local client configuration; do not dump its contents, which may contain credentials.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab api-resources --namespaced=truekubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab api-versionskubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab explain pods.spec.containers --api-version=v1The last command describes container configuration fields, rather than the contents of a running container. These commands need server access except local config operations.
Wait for a condition and distinguish exec
A bounded wait is useful when a known object is expected to become ready. A timeout signals that the requested condition was not observed within the bound; it does not identify a cause. exec runs a program inside a container, not an SSH session. It can change state and requires separate permission. Use only a reviewed benign command in an approved fixture; the chosen image must contain the program. Do not execute arbitrary commands while debugging.
kubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab wait --for=condition=Ready pod/catalog-a --timeout=30skubectl --kubeconfig ./lab.kubeconfig --context bytemind-lab -n book-lab exec pod/catalog-a -c app -- printf "%s\n" catalogThe first asks for Ready=True. The second runs printf inside app, if available, and would print catalog. The double dash separates kubectl arguments from container command arguments; it does not create a shell. Neither operation has been run here.
Common mistakes and next step
Do not treat get output as a manifest to apply blindly; do not infer health from the STATUS column alone. A permission error is different from an object not being found. Check scope, then authorization, before investigating the workload. Practice: use pods.json and diagnostic.json to choose commands and explain the evidence. Next, learn how to propose and review a small configuration change.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Inspect resources with kubectl — knowledge check
Apply the lesson concepts to original offline scenarios.
Which command gives a compact inventory of Pods?
Which command targets the previous terminated app container instance?
catalog-b has Running phase but Ready=False. What follows?
What does explain pods.spec.containers describe?
What does a wait timeout establish?