StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 2 · kubectl Inspection & Debugging

Logs & Exec

easyContainer Logskubectl Exec—No data yet

Problem statement

The only debugging tool in use is deleting the pod and hoping; nobody reads what the process said or checks the filesystem it sees. The namespace triage has the evidence - a long-running worker, a two-container pod, and one workload that crashed three times before it finally connected.

About this exercise

Two commands turn a pod from a black box into something you can question:

  • kubectl logs prints what a container wrote to standard output. Three things about it decide whether you get the right text: a pod with more than one container needs to be told which one (without it, the first container answers and the one you wanted stays silent); a container that has restarted keeps the previous instance's log available separately - that is where a crash's last words are, since the running instance's log starts empty; and the output can be limited to the last N lines instead of everything.
  • kubectl exec runs a command inside a running container. It answers questions the API cannot: what files exist, what the process sees, what an environment variable really holds.

kubectl logs --help and kubectl exec --help document the flags.

The seeded workloads: ledger-worker prints two lines and stays alive; invoice-pair runs two containers, renderer and shipper, each printing its own marker, and the renderer writes a file at /work/invoice.txt; mailer-crash failed three times, each attempt announcing its number, before the fourth succeeded.

How this project is graded

The grader compares your saved answers against what the cluster and the containers actually contain. Everything here is read-only.

What you will build

Six answers in answers/, listed in answers/questions.md:

ledger.txt        what ledger-worker has printed
ledger-tail.txt   only the last line ledger-worker printed
mailer-now.txt    what the mailer-crash container running now printed
mailer-prev.txt   what the previous mailer-crash container printed
shipper.txt       what the shipper container of invoice-pair printed
rendered.txt      the contents of /work/invoice.txt inside the renderer container

Step 1 - what the process said

Capture the worker's output, and then only its last line.

log_read_returns_the_seeded_markers and tail_limit_returns_exactly_that_many_lines should pass

Step 2 - the instance that died

Capture the current instance's log and the failed instance's log. They are different instances of the same container, and they say different things.

current_instance_log_read and previous_instance_log_read should pass

Step 3 - the right container, and inside it

Get the shipper's output out of a two-container pod, and read a file that exists only inside the renderer.

container_selector_honored_on_multi_container_pod and exec_reports_in_container_truth should pass

When every test passes

You have:

  • The process's own account of what happened, not a guess from outside
  • The crashed instance's last words, which vanish from view the moment it restarts
  • Log reads that name their container instead of taking whatever comes first
  • A way to ask questions inside a running container

You do not have yet:

  • The cluster's account. When a pod never starts at all there are no logs to read - the events are the only witness, and they are the next exercise.

Verify

Click Test after every step.

More in kubectl Inspection & Debugging

See the module
Reading Cluster StateAnswer real questions about a running namespace with get and describe - wide placement, exact field extraction, sorted listings and the events section.—No data yeteasyEvents & Field SelectorsDiagnose stuck workloads from the cluster's own record - events filtered by object, reason and type, each failure named by its cause.—No data yeteasyCluster Triage KitOne read-only sweep over a namespace: placement and state, log and in-container evidence, and an event-rooted diagnosis for every broken workload.—No data yeteasy

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.