Kubernetes - Normalize Application Output with an Adapter Container
An adapter container sits in the same Pod as the main application and transforms its output without modifying the application itself. The two containers share a volume - the app writes to it, the adapter reads and reformats. Any consumer that reads the adapter container's logs gets a clean, normalized format regardless of what the app produces.
Task 1 - Normalize App Output with an Adapter Container
Both containers share an emptyDir volume. The app container appends pipe-delimited lines to a log file on the shared volume. The adapter container reads the same file and pipes each line through sed to replace the delimiters. The adapter logs show ERROR SomeTimestamp something broke with pipe characters replaced by spaces.
Steps:
- Create a Pod named
adapter-podwith two containers and a sharedemptyDirvolume namedlogsmounted at/logs:- Container
app, imagebusybox, command["sh", "-c", "while true; do echo 'ERROR|SomeTimestamp|something broke' >> /logs/app.log; sleep 3; done"] - Container
adapter, imagebusybox, command["sh", "-c", "while true; do cat /logs/app.log | sed 's/|/ /g'; sleep 3; done"]
- Container
The ambassador pattern applies a similar idea to outbound traffic routing: Kubernetes - Proxy Outbound Traffic with an Ambassador Container.