🧾 Multi-Container Pods — Volume Mounting Notes

🔹 Core Concept

In a multi-container Pod, all containers: - Share the same network namespace (can communicate via localhost) - But do not automatically share storage

To share data between containers, we use volumes — specifically EmptyDir for temporary shared storage within the Pod.


🔹 Volume Definition vs. Mounting

Level Field Purpose
Pod level spec.volumes Defines a volume resource that can be used by any container in the Pod
Container level volumeMounts Mounts that Pod-level volume inside a container’s filesystem

🧠 The Pod defines the volume, but each container decides whether to use (mount) it or not.


🔹 Key Rule

Mounting a volume in every container is not mandatory.
A Pod will run successfully even if only some containers mount the volume.

However: - If the question explicitly says “the volume should be attached and mounted into each container,” you must mount it in all containers. - If not mentioned, mount it only where it’s needed.


💡 Summary Table

Scenario Does Pod Run? Exam Correctness Real-world Practice
Volume mounted only in containers that need it ✅ Yes ✅ Correct (if not explicitly required for all) ✅ Best practice
Volume mounted in all containers ✅ Yes ✅ Correct (if question requires it) ⚙️ Acceptable but unnecessary
Volume defined but not mounted anywhere ✅ Yes ❌ Logically incorrect 🚫 Avoid

⚙️ Why a Pod Still Runs Without Mounting in All Containers

Kubernetes validates: - The volume exists at the Pod level. - Each volumeMount refers to a valid volume name.

It does not enforce that every container must mount every volume.
So even if one container doesn’t mount it, the Pod is considered valid and runs normally.


🎯 Practice — Exam-Style Question Patterns

🧩 Question 1 — Must mount in all containers

“Create a Pod with multiple containers. The Pod should have a volume attached and mounted into each container.”

✅ You must define volumeMounts in every container, even if not all use the volume.


🧩 Question 2 — Mount only where needed

“Create a Pod with three containers. Container c1 writes data to a shared volume, and container c2 reads it. Container c3 prints its node name.”

✅ Only c1 and c2 need the volume.
Mount it only in those containers.


🧩 Question 3 — Available to all containers

“A Pod should have a volume available to all containers, but only container c2 writes data to it.”

✅ The phrase “available to all containers” means mount it in every container, even if only one writes data.


🧩 Question 4 — Shared EmptyDir

“Create a multi-container Pod using an EmptyDir volume shared between containers writing and reading logs.”

✅ Mount the volume only in the containers that write or read logs.


💬 Exam Tip

Phrase in Question What to Do
“mounted into each container” Mount in all containers
“shared between containers that do X and Y” Mount only in those containers
No mention of mounting scope Mount only where logically required

✅ TL;DR

A Pod runs fine even if a defined volume isn’t mounted in every container.
Mounting in all containers is only required when explicitly stated in the question or when each container needs access to the same data.