๐ง First: What is a Namespace in Linux?
A namespace in Linux is a boundary or an isolation mechanism.
It decides what a process is allowed to see on the system.
Think of it like:
A private room inside a house.
You only see whatโs inside your room, not the whole house.
Containers rely heavily on Linux namespaces.
๐งฉ Types of Linux Namespaces
Some key ones used by containers:
| Namespace | What it isolates | Example |
|---|---|---|
| NET | Network | Each container gets its own virtual network stack |
| PID | Processes | Each container sees only its own processes |
| IPC | Inter-process communication | Shared memory, semaphores |
| UTS | Hostname | Each container can have its own hostname |
| MNT | Filesystems | Each container has its own root filesystem |
Kubernetes Pods mainly use NETWORK + IPC + UTS namespaces.
๐ Now: What is a Shared Namespace in a Pod?
- A Pod is NOT a container.
- A Pod is a wrapper that can contain multiple containers, and those containers share some namespaces.
That means:
๐ All containers inside the same Pod can see the same network, hostname, and IPC resources.
This is why we say:
Containers inside a Pod share namespaces.
Letโs break it down.
๐ 1. Shared NETWORK Namespace (Most Important)
What it means:
All containers inside a Pod:
- Share the same IP address
- Share the same network interface
- Can talk to each other using localhost
- Can use the same ports
Example:
Pod has two containers:
- Container A runs on port 8080
- Container B runs on port 9000
Both can communicate like this:
Container A โ http://localhost:9000
Container B โ http://localhost:8080
They donโt need a Service to talk to each other.
๐ This is why we say: Pods = shared network namespace.
๐พ 2. Shared STORAGE (Volumes)
Containers inside one Pod share:
- mounted volumes
- shared directories
Example:
/shared-data
Both containers can read/write to the same folders.
๐ง 3. Shared UTS Namespace (Hostname)
Containers inside a Pod share the same hostname.
If you run:
hostname
in container A and container B โ you get the same result.
๐ 4. Shared IPC Namespace
IPC = Inter-Process Communication.
Containers can:
- share memory
- send signals
- use semaphores
This is optional and depends on Pod settings.
๐ฏ Simple Real-World Analogy
๐ A Pod = a shared apartment
๐ช Containers = roommates
๐ Network namespace = shared WiFi
All containers use the same IP โ like one internet connection.
๐งฑ Volumes = shared storage room
All containers can use the same shared folder.
๐ Namespaces = private walls
Containers cannot see outside the Podโs isolation.
๐ง Summary
Namespace = a sandbox that isolates what a container can see.
Shared Namespace = multiple containers inside the same Pod share the same sandbox.
So:
- Each Pod gets one IP, not each container
- Containers inside a Pod share the same networking environment
- Containers inside a Pod can talk using localhost
Top comments (0)