Marcio Cunha

Overlay Network: How Containers on Different Servers Share a Virtual Network

Learn how overlay networks allow Docker and Kubernetes containers on separate physical servers to communicate as if they were running on the same machine.

Marcio Cunha12 min
Also available in:EspañolPortuguês
Summary
  • Network virtualization removes the physical barrier that prevents containers on separate machines from talking directly.
  • Encapsulation wraps traditional network packets inside new packets for secure transport across the physical internet.
  • Tools like VXLAN and Geneve encapsulate traffic by adding an extra header without altering original application data.
  • State management and service discovery automate tracking virtual IP addresses in real time.
  • Choosing between overlay networks and traditional bridges requires balancing processing performance and multi-tenant isolation.

The Challenge of Connecting Distinct Machines in the Container World

When building modern applications using containers, which are lightweight packages holding everything a program needs to run, we frequently distribute workloads across multiple physical computers or servers. In practice, imagine your web application runs on server A while the database runs on server B. By default, each machine maintains its own isolated networking universe, meaning the container on server A cannot reach the container on server B using traditional local IP addresses alone.

This strict isolation is fantastic for security, but terrible for microservices communication. Without a proper networking infrastructure, engineering teams would be forced to expose public ports on the internet just for internal systems to exchange messages, creating severe security vulnerabilities. Solving this exact impasse is why virtualized network architectures exist, enabling secure logical bridges over existing physical infrastructure without requiring additional network cables or switches.

The Fundamental Concept of Overlay Networks

An overlay network is a logical network built on top of another underlying network, known as the underlay. To understand this dynamic in everyday life, think of elevated highways in a major city: vehicle traffic flows on a suspended road using the same pillars and territorial space as the traditional streets below without directly interfering with local traffic. In computer science, the underlay network represents physical cables and routers, while the overlay is the virtual communication layer created purely through software.

In practice, when a container sends data packets to another container on a distant server, the overlay technology intercepts this message and applies a technique called encapsulation. The original application packet is placed inside a brand-new network packet, much like putting a confidential letter inside a larger envelope addressed directly to the destination server. This wrapped packet travels across the standard physical network, and upon reaching the destination server, the operating system opens the outer envelope, extracts the original message, and delivers it to the correct container.

Encapsulation and Protocols in Practice

The mechanism behind encapsulation relies on standardized protocols that append extra information to network traffic. One of the most popular methods used in large-scale environments, such as Docker Swarm and Kubernetes, is VXLAN, which stands for Virtual Extensible LAN. In practice, VXLAN takes the original Ethernet packet from the container, adds a UDP header, and transmits it across the physical network. This allows the virtual network to create up to 16 million isolated segments within the same physical infrastructure.

Another widely adopted protocol in modern solutions is Geneve, designed to be exceptionally flexible and extensible. While VXLAN has a more rigid header format, Geneve allows custom metadata to travel alongside data packets. In practice, this means monitoring and security tools can inject context information directly into network traffic, simplifying audits and troubleshooting in complex distributed systems without sacrificing performance.

Service Discovery and IP Mapping

Creating communication tunnels between servers is only half the battle; the system must also know precisely where each container resides at the moment of a request. Because containers are ephemeral—born, dying, and migrating across servers dynamically—hardcoding static IP addresses is unviable. To solve this, orchestration platforms maintain an internal mapping database, acting like an automated phonebook that updates each service's location in real time.

When an application container attempts to reach the database using a friendly name like 'production-db', an internal name resolution component translates that name into the correct virtual IP address inside the overlay network. Next, the system consults the distributed routing table to figure out which physical server hosts that specific IP at that exact second. This process happens in fractions of a second, ensuring data exchange occurs completely transparently for developers and end users alike.

Performance Trade-offs and Network Overhead

No technology in software engineering comes without costs, and overlay networks are no exception. The primary concern revolves around processing overhead and bandwidth consumption caused by encapsulation and decapsulation processes. Because every data packet must gain extra headers before transmission and be processed again at the receiving end, server CPU usage increases slightly, and the usable network packet size decreases—a phenomenon known in the field as MTU overhead.

In practice, for workloads demanding massive real-time data transfers, such as video processing or high-frequency analytical databases, overlay-induced performance loss can become a noticeable bottleneck. In these specific scenarios, engineers frequently evaluate alternatives like host-networking or specialized hardware solutions, though they sacrifice the portability and ease of configuration that make containers so attractive for daily development.

Conclusion and Practical Guidelines

The adoption of overlay networks revolutionized how we build and operate container-based architectures, removing physical boundaries that once limited communication between distinct servers. Understanding the fundamentals of encapsulation, transport protocols, and dynamic address mapping empowers engineering teams to design resilient, secure, and easily scalable distributed systems. Carefully weighing performance trade-offs ensures that architectural choices perfectly match business requirements without compromising the operational stability of the infrastructure.