Challenge, Easy,  on  Kubernetes

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-pod with two containers and a shared emptyDir volume named logs mounted at /logs:
    • Container app, image busybox, command ["sh", "-c", "while true; do echo 'ERROR|SomeTimestamp|something broke' >> /logs/app.log; sleep 3; done"]
    • Container adapter, image busybox, command ["sh", "-c", "while true; do cat /logs/app.log | sed 's/|/ /g'; sleep 3; done"]

The ambassador pattern applies a similar idea to outbound traffic routing: Kubernetes - Proxy Outbound Traffic with an Ambassador Container.