0
0
Kubernetesdevops~30 mins

Container logging architecture in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Container Logging Architecture in Kubernetes
📖 Scenario: You are working as a DevOps engineer managing a Kubernetes cluster. You want to set up a simple container logging architecture to collect logs from your application pods and store them centrally for easy access and troubleshooting.
🎯 Goal: Build a basic container logging setup in Kubernetes by creating a pod with a container that writes logs, configure a log path variable, collect logs using a sidecar container, and finally display the collected logs.
📋 What You'll Learn
Create a pod manifest with a main container that writes logs to a file
Add a configuration variable for the log file path
Add a sidecar container that reads the log file and outputs logs
Display the logs collected by the sidecar container
💡 Why This Matters
🌍 Real World
Centralized logging helps DevOps teams monitor and troubleshoot applications running in Kubernetes clusters efficiently.
💼 Career
Understanding container logging architecture is essential for roles like DevOps engineer, site reliability engineer, and cloud administrator.
Progress0 / 4 steps
1
Create a pod manifest with a main container that writes logs
Create a Kubernetes pod manifest named logging-pod.yaml with a pod called logger. It should have one container named app using the image busybox. The container should run the command sh -c "while true; do echo 'Log entry' >> /var/log/app.log; sleep 5; done" to write logs continuously to /var/log/app.log. Use an emptyDir volume named log-volume mounted at /var/log.
Kubernetes
Need a hint?

Use emptyDir volume to share logs inside the pod. The app container writes logs to /var/log/app.log.

2
Add a configuration variable for the log file path
Add an environment variable named LOG_PATH with the value /var/log/app.log to the app container in the logging-pod.yaml manifest.
Kubernetes
Need a hint?

Use the env field inside the app container to add the LOG_PATH variable.

3
Add a sidecar container to read and output logs
Add a second container named log-reader to the pod. Use the image busybox. It should mount the same log-volume at /var/log and run the command sh -c "tail -f /var/log/app.log" to continuously output the logs.
Kubernetes
Need a hint?

The log-reader container shares the log-volume and tails the log file to output logs.

4
Display the logs collected by the sidecar container
Run the command kubectl logs logger -c log-reader to display the logs output by the log-reader container.
Kubernetes
Need a hint?

This command fetches logs from the log-reader container inside the logger pod.