0
0
Kubernetesdevops~30 mins

Multi-container Pods concept in Kubernetes - Mini Project: Build & Apply

Choose your learning style9 modes available
Multi-container Pods concept
📖 Scenario: You are working on a Kubernetes cluster for a simple web application. This application needs two containers running together in the same Pod: one container serves the web content, and the other container logs the web server activity.
🎯 Goal: Create a Kubernetes Pod manifest with two containers inside it. One container runs the nginx web server, and the other container runs a simple busybox container that logs messages to a shared volume.
📋 What You'll Learn
Create a Pod manifest named multi-container-pod.yaml.
Define two containers inside the Pod: web-server using the nginx image and logger using the busybox image.
Add a shared emptyDir volume named shared-logs mounted at /var/log in both containers.
The logger container should run the command sh -c 'while true; do echo Logging... >> /var/log/log.txt; sleep 5; done' to simulate logging.
The web-server container should expose port 80.
💡 Why This Matters
🌍 Real World
Multi-container Pods are used when containers need to work closely together, like a web server and a helper container for logging or data processing.
💼 Career
Understanding multi-container Pods is essential for Kubernetes administrators and DevOps engineers to design efficient and maintainable applications.
Progress0 / 4 steps
1
Create the basic Pod manifest with metadata
Create a YAML file named multi-container-pod.yaml with a Pod manifest. Add apiVersion: v1, kind: Pod, and metadata with name: multi-container-pod.
Kubernetes
Need a hint?

Start by defining the Pod with its API version, kind, and give it a name under metadata.

2
Add two containers with images and ports
Under spec, add two containers: one named web-server using image nginx exposing port 80, and another named logger using image busybox. Do not add commands or volumes yet.
Kubernetes
Need a hint?

Remember to indent containers properly under spec and list each container with its name and image.

3
Add shared volume and mount paths, and logger command
Add an emptyDir volume named shared-logs under spec.volumes. Mount this volume at /var/log in both containers. Add the command sh -c 'while true; do echo Logging... >> /var/log/log.txt; sleep 5; done' to the logger container.
Kubernetes
Need a hint?

Use emptyDir: {} to create a shared volume. Mount it in both containers at /var/log. Add the command as a list of strings in the logger container.

4
Display the final Pod manifest
Print the complete content of multi-container-pod.yaml to verify your multi-container Pod manifest.
Kubernetes
Need a hint?

Use print(open('multi-container-pod.yaml').read()) to display the file content if running locally, or simply output the YAML content as a string.