Lab 01-14: Native Sidecar for Application Logs
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, usingbusybox:1.37.0. - Exactly one native sidecar named
logger, also usingbusybox:1.37.0. Define it underinitContainerswith its ownrestartPolicy: Always. - One shared
emptyDirvolume namedapp-logs, mounted at/var/log/appin both containers without subPath. The application mount must be writable. loggercreates/var/log/app/events.logif it does not exist, then continuously streams new lines from that file to its standard output.- Give
loggeran exec startup probe with commandtest -f /var/log/app/events.log, period1second, failure threshold30, timeout1second, success threshold1, and no initial delay. appkeeps appending a line beginning withapp-eventto 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.