Challenge
DifficultyEasy
Learner activity No attempts yet

Lab 01-14: Native Sidecar for Application Logs

Use a native sidecar to stream application logs from a shared volume.

Lab 01-14: Native Sidecar for Application Logs

Time: About 20 minutes · Requires Kubernetes 1.33+

Lab 01-09 practices two regular containers sharing a Pod. In this exercise, a supporting container performs useful work for the application and uses Kubernetes' native sidecar lifecycle.

Use the dev-machine terminal. The namespace sidecar-lab is prepared for you. This lab starts independently.

Create the application and sidecar

Create a standalone Pod with these requirements:

  • Name: app-with-sidecar; namespace: sidecar-lab; Pod restart policy: Always.
  • Exactly one regular application container named app, using busybox:1.37.0.
  • Exactly one native sidecar named logger, also using busybox:1.37.0. Define it under initContainers with its own restartPolicy: Always.
  • One shared emptyDir volume named app-logs, mounted at /var/log/app in both containers without subPath. The application mount must be writable.
  • logger creates /var/log/app/events.log if it does not exist, then continuously streams new lines from that file to its standard output.
  • Give logger an exec startup probe with command test -f /var/log/app/events.log, period 1 second, failure threshold 30, timeout 1 second, success threshold 1, and no initial delay.
  • app keeps appending a line beginning with app-event to the shared log at least once every two seconds.
  • The Pod must be Running and Ready, and both containers must remain running.

The sidecar's startup probe must succeed before the main application starts. It should continue running alongside the application rather than exiting like an ordinary init container.

Verify the supporting behavior

The automatic checker appends one uniquely identified validation line to the application log and waits for it to appear in logger output. It also checks that new application events continue to be written and that the same Pod and containers remain running. Do not alter the Pod while this brief experiment runs.

Choose your own commands and manifest. Leave the Pod running until verification completes.