DEV Community

Shiva Charan
Shiva Charan

Posted on

Shared Namespaces

๐Ÿง  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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)