Add a Sidecar Log Tailer to an Existing Deployment
Scenario
A logging application called logger-app is running in the logging namespace. The main app container writes log entries to /var/log/app.log every 5 seconds, but there is currently no way to observe these logs from outside the container.
Your task is to add a co-located sidecar container to the same pod that reads the log file through a shared emptyDir volume and streams it to stdout via kubectl logs.
Task
Update the existing logger-app Deployment in the logging namespace by adding a co-located sidecar container:
- Container name:
sidecar - Image:
busybox:stable - Command:
tail -f /var/log/app.log - Mount the existing shared volume
log-volumeso the co-locatedsidecarcan read the log file written by theappcontainer
Sidecar container streaming application logs using tail -f.
Once applied, verify the sidecar is streaming logs correctly:
kubectl logs -n logging -l app=logger-app -c sidecar --tail=10
Do not remove or modify the existing app container or the log-volume volume definition. Only add the sidecar container and its volume mount.
Hint — Add the sidecar container
Edit the Deployment and add a second container under spec.template.spec.containers:
kubectl edit deployment logger-app -n logging
The sidecar container needs a volumeMount for the same log-volume that the app container already uses.