Problem statement
report-api crashes on boot: it reads /etc/app/app.conf and the file is not there yet, because whatever produces it is still running. The workaround copy-pasted across the fleet is a sleep loop in the entrypoint - the app starts anyway, sleeps, and hopes the file turns up. Namespace bundle-preflight already holds ledger-api, a pod whose preparation step fails outright, and it is your evidence for what the platform does when preparation cannot succeed.
About this exercise
A pod is not one container, it is a group of containers that share a lifecycle, a network identity and volumes. Init containers are the members of that group that run before the app containers, one at a time, in the order they are declared, each one running to completion before the next begins. Only when the last one has exited successfully does Kubernetes start the app containers.
That gives you two things the sleep loop never had:
- Ordering as a guarantee, not a race. An app container that starts at all is an app container whose preparation already finished. There is nothing left to poll for.
- Failure that stops the pod instead of hiding in it. If an init container exits non-zero the app containers are never started, and the pod records which init container failed and with what exit code. A sleep loop, by contrast, produces a running pod serving nothing.
Init containers and app containers see separate filesystems, so an artifact prepared by one is invisible to the other unless they share a volume. An emptyDir volume is created empty when the pod is scheduled and lives as long as the pod; every container that mounts it sees the same directory, and each may mount it at a different path.
kubectl explain pod.spec.initContainers and kubectl explain pod.status.initContainerStatuses are the reference for the fields and for what the cluster records about each one.
How this project is graded
The grader reads the live pods: what your pod declares, when each container actually started according to the timestamps the cluster recorded, and what the app container can read from inside itself. The seeded ledger-api is never repaired or deleted - it is read, and your saved answers are compared against what it reports. Re-apply your manifest after every edit; the cluster is graded, not the file.
What you will build
A pod in manifest.yaml, applied to the cluster, and two answers in answers/:
pod report-api, namespace bundle-preflightone emptyDir volume, mounted by every container below init container fetch-config busybox:1.36 mounts the volume at /shared writes the line mode=production as /shared/app.conf init container seal-config busybox:1.36 mounts the volume at /shared appends the line sealed=true to that same file app container api busybox:1.36 mounts the volume at /etc/app stays running, and finds the prepared file at /etc/app/app.conf holding both lines in that order
answers/blocked-phase.txt the phase the cluster reports for ledger-api (that word alone) answers/blocked-exit.txt the exit code the cluster recorded for the init container of ledger-api (that number alone)
Step 1 - prepare before you start
Give report-api the two preparation steps and the shared volume, and apply it. The app container must reach a running state with the prepared file already at /etc/app/app.conf.
init_containers_prepare_a_shared_volume, app_container_starts_only_after_init_completes and prepared_config_present_at_the_app_path should pass
Step 2 - one after another
The two preparation steps are not interchangeable: the file must end up with mode=production first and sealed=true second, and the cluster's own record of when each finished must agree with the order you declared them in.
init_containers_ran_in_declared_order should pass
Step 3 - when preparation fails
Read what happened to ledger-api and save the two values exactly. Do not repair it - a pod stuck before its app container is the behaviour being demonstrated.
failing_init_keeps_its_pod_out_of_running and init_failure_exit_code_recorded should pass
When every test passes
You have:
- An app container that cannot start before what it needs exists
- Two containers in one pod handing an artifact to each other through a shared volume
- Preparation steps that run in a declared order rather than a hopeful one
- The cluster's own record of a failed preparation, with the exit code that caused it
You do not have yet:
- Anything running beside the app for its whole life. Init containers are finished by the time the app starts; a companion that runs alongside it is the next exercise.
Verify
Click Test after every step.
