StaffCoder
Kubernetes
15 modules · 60 challengesSign up
Module 5 · Multi-Container Pods

Composed Application Pod

easyMulti-Container Pod CompositionInit Containers & Sidecars—No data yet

Problem statement

The storefront does not ship as an application, it ships as a quartet: something that prepares its config, the application itself, a shipper that gets its log file off disk, and a helper it calls on every order. Run them apart and none of it works - the app reads a config that is not there, writes a log file nothing can see, and calls a helper it has no way to address. Namespace bundle holds storefront-blocked, the same quartet pointed at a config source it cannot reach; read it, do not repair it.

About this exercise

This brings together the topic's three exercises:

  • Preparation - an init container that runs to completion before the app container starts, handing over its artifact in a shared volume (Init Containers)
  • A companion for the whole run - a sidecar sharing a volume with the app and republishing its log file on its own stream (Sidecar Log Shipper)
  • Cooperation over localhost - containers of one pod sharing a single network identity and a single set of ports (Localhost Cooperation)

One idea governs all of it: a pod is the unit of co-scheduling. Its containers start in a defined relationship, live on one node, share one address and can be handed the same directory - and none of that is available to processes in separate pods. Everything the quartet needs from each other, it gets from being one pod.

kubectl explain pod.spec is the reference for the fields, and kubectl explain pod.status.initContainerStatuses for what the cluster records about preparation.

How this project is graded

The grader reads the live pods: what your pod declares, the timestamps the cluster recorded for each container, what the app container can read from inside itself, what it gets back from the helper, and what each container's log stream carries. storefront-blocked is read, never repaired - your saved answer is compared against what the cluster reports for it. 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 one answer in answers/:

pod storefront, namespace bundle

two emptyDir volumes, one for config and one for logs

init container config-writer busybox:1.36 mounts the config volume at /shared writes the line mode=production as /shared/app.conf

container api busybox:1.36 mounts the config volume at /etc/app and the logs volume at /var/log/app the legacy application, already in the starter manifest: reads /etc/app/app.conf, prints STOREFRONT-API STARTED on its own standard output, appends one line ORDER <n> accepted to /var/log/app/orders.log per cycle, and requests http://localhost:8080/health, printing each response container shipper busybox:1.36 mounts the logs volume at /var/log/app its standard output carries the lines of /var/log/app/orders.log, from the first line onward container helper busybox:1.36 prints HELPER-LISTENING 8080 on its own standard output, then serves HTTP on port 8080, answering a request for /health with the single line HELPER-OK

answers/blocked.txt the exit code the cluster recorded for the preparation step of storefront-blocked (that number alone)

The tests

  • Init_app_starts_only_after_init_completes - the preparation step finished successfully before the app container began
  • Init_config_present_at_the_app_path - the app container finds the prepared config at its own mount path
  • Init_seeded_failure_holds_pod_out_of_running - a preparation that fails leaves its pod out of Running, with the exit code on record
  • Localhost_api_reaches_helper_in_pod - the app's call to the helper over localhost is answered
  • Localhost_every_container_reports_one_pod_ip - all three running containers report the pod's single address
  • Sidecar_shipper_stdout_carries_the_app_file_lines - the app's log file leaves the pod as the shipper's log stream
  • Sidecar_per_container_log_selection_isolates_streams - each container's stream carries only its own output
  • Composition_one_pod_runs_the_whole_quartet - one pod, one preparation step and three running containers, wired to the two volumes

When every test passes

You have:

  • One pod that prepares itself, runs, ships its own logs and answers its own calls
  • An application whose config exists before its first line of code runs
  • A file on disk turned into a cluster log stream by a container beside it
  • Two processes cooperating over an address neither of them had to discover
  • Four containers whose output stays four separate streams
  • The next topic unlocked

Verify

Click Test.

More in Multi-Container Pods

See the module
Init ContainersGate an app container on init containers that prepare its config in a shared volume, prove the declared order from the cluster's own timestamps, and read what a failed preparation records.—No data yeteasySidecar Log ShipperPair a legacy app that logs to a file with a sidecar that shares its volume and republishes those lines on its own stream, then read each container's log separately.—No data yeteasyLocalhost CooperationRun an app and its helper as containers of one pod talking over localhost, confirm the shared pod IP from inside both, and read what happens when two containers want the same port.—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.