DEV Community

Diana
Diana

Posted on

Kubernetes: How Your Apps Find Each Other 🌐

Introduction: From Addresses to Orchestration

In my previous posts, we covered the high-level architecture of Kubernetes and the networking fundamentals that help explain how devices find each other:

  • IP addresses (street names + house numbers)
  • Ports (doors)
  • Private vs. Public IPs
  • Localhost
  • DNS

Now it's time to connect the dots. Inside a Kubernetes cluster:

  • Pods get their own IP addresses
  • Services act as stable phone book entries so nothing gets lost when Pods come and go
  • Ingress controllers manage traffic from the outside world

Sound familiar? It's every concept from Networking 101, applied to containers.


Kubernetes Networking: The Building's Internal Address System 🏒

Let's bring our networking knowledge into the Kubernetes building. Remember, we have:

  • A cluster (the building)
  • Nodes (the floors)
  • Pods (the rooms)

Cluster, Nodes, and Pods - The Building Analogy

In Kubernetes, every Pod gets its own IP address. That's like every room in our building getting its own unique address.

The Three Networking Challenges Kubernetes Solves

Challenge Question Building Analogy
1. Pod-to-Pod Communication How does Room 101 talk to Room 205? Rooms calling each other directly
2. Service Discovery How do I find the coffee shop if it moved? A building directory that stays up to date
3. External Access How do customers outside find us? Getting visitors into the building

Let's tackle each one.


Challenge 1: Pod-to-Pod Communication πŸ—£οΈ

In Kubernetes, every Pod can talk to every other Pod directly using their IP addresses, no special configuration needed.

It's like every room in the building having its own phone number, and every phone being able to call any other phone.

Administrators can restrict this later with NetworkPolicies, but out of the box, everything is open.

Pod-to-Pod Communication across Nodes

Every room can call every other room directly, even across floors!

Key Point: Pods can communicate across Nodes. Kubernetes handles the routing behind the scenes.

  • Room 102 (Floor 1) β†’ Room 202 (Floor 2) βœ…
  • Room 102 (Floor 1) β†’ Room 101 (Floor 1) βœ…
  • Any room β†’ Any other room βœ…

But here's the problem...


Challenge 2: Service Discovery: The Problem with Pod IP Addresses 😰

Remember how we said Pods are ephemeral? They come and go. They crash and get replaced. They scale up and down. Every time a Pod is replaced, it gets a new IP address.

Imagine this scenario in our building:

Monday:
  Coffee Shop is in Room 101 (IP: 10.244.1.5)
  Everyone knows to go to Room 101 βœ…

Tuesday:
  Coffee Shop crashed! Kubernetes restarts it.
  New Coffee Shop is in Room 205 (IP: 10.244.2.10)
  Nobody knows the new address ❌

Wednesday:
  We scaled to 3 Coffee Shops.
  They're in Room 101, Room 205, and Room 302.
  Which one do customers go to?! 🀯
Enter fullscreen mode Exit fullscreen mode

This is like a coffee shop that changes its street address every day. Your regular customers would never find you! This is where having something stable, something permanent that people can always rely on, makes all the difference.

That's exactly what Services solve.


Kubernetes Services: The Building Directory πŸ“ž

A Service in Kubernetes is a stable address that always points to the right Pods, no matter where they are or how many there are.

Remember the DNS phone book from Networking 101? Services work the same way. They're stable phone book entries for your Pods. Think of it as the building's front desk directory.

Instead of telling customers "Go to Room 101" (which might change tomorrow), you tell them "Call the Coffee Shop extension." The front desk always connects them to the right room.

Without a Service:
  Customer β†’ "Where's the coffee shop?" β†’ ??? 😡

With a Service:
  Customer β†’ "Coffee Shop, please" β†’ Front Desk β†’ Room 101 βœ…
                                                  β†’ Room 205 βœ…
                                                  β†’ Room 302 βœ…
Enter fullscreen mode Exit fullscreen mode

What a Service gives you:

Stable IP Address

Every Service gets a ClusterIP that never changes. Pods come and go, but the Service address stays the same.

Load Balancing

Distributes incoming traffic across multiple Pods so no single one gets overloaded.

3 coffee shops open in the building? The front desk doesn't send every customer to the same one. It spreads them out so no single shop gets overwhelmed. The Service does this automatically as you scale up your Pods.

DNS Name

Just like google.com maps to an IP address, Kubernetes gives every Service a name like:

coffee-shop.default.svc.cluster.local

So Pods can find each other by name instead of memorizing IPs.

Part Meaning
coffee-shop Service name
default Namespace
svc Service
cluster.local "Inside this cluster"

What's a Namespace? Going back to our building analogy, Namespaces are like the different departments on each floor. Marketing, Engineering, HR, all in the same building but keeping their stuff separate. How teams separate things is case by case depending on their setup.

These DNS names only work inside the cluster's private network. Remember how devices on your home network find each other using private IPs like 192.168.1.x? Same idea here.

How Services Find Pods: Labels and Selectors 🏷️

Services don't track Pods by their IP addresses (because those change). Instead, they use labels. Every Pod gets a label, and the Service is configured to find all Pods with a matching label.

Service: "Find all Pods labeled app=coffee-shop"

  Pod 1 (Room 101) - label: app=coffee-shop  βœ… Match!
  Pod 2 (Room 205) - label: app=coffee-shop  βœ… Match!
  Pod 3 (Room 302) - label: app=coffee-shop  βœ… Match!
  Pod 4 (Room 110) - label: app=bakery       ❌ Not a match
Enter fullscreen mode Exit fullscreen mode

It's like the front desk has a rule: "Anyone wearing a Coffee Shop uniform works at the coffee shop."

New employees (Pods) automatically get found, and ones who leave are automatically removed. No manual updates needed.


Service Types + Ingress πŸ”§

Kubernetes gives you different types of Services, plus a separate resource called Ingress. Let's look at the ones that matter most when you're getting started.

1. ClusterIP: The Internal Extension πŸ“ž

Default type, internal communication only

This is like an internal phone extension. Only people inside the building can use it. Customers outside can't dial this number.

ClusterIP Service - Internal Only

When to use it: When your services only need to talk to each other inside the cluster. For example, your frontend app calling your backend API.

2. NodePort: The Side Entrance πŸšͺ

Exposes the Service on each Node's IP at a static port

This is like adding a side entrance to the building. People outside can now get in, but they need to know which building (Node) to go to and which door (port) to use.

NodePort Service - External via Node Port

When to use it: For development and testing, or when you want quick external access without a cloud load balancer.

3. Ingress: The Traffic Cop 🚦

A separate resource (not a Service type) that routes external traffic to multiple Services based on rules

Ingress is like a traffic cop standing in the lobby of your building. Visitors walk in, and the traffic cop checks where they're trying to go and directs them to the right department.

Heading to coffee.com/menu? Go left. coffee.com/order? Go right. tea.com? Take the elevator to floor 3.

Instead of having a separate entrance for every service, you have one entrance with a traffic cop handling all the routing.

Ingress - Traffic Cop routing to multiple Services

When to use it: When you have multiple services and want one entry point with smart routing. It gives you features like SSL termination and path-based routing.


Challenge 3: External Access 🌍

How do real users reach your app from the internet? We introduced Ingress above, but there's more to the picture:

  • LoadBalancers, service meshes (like Istio), and how domains even get routed to your cluster
  • The setup looks very different on cloud (a lot is handled for you) vs. on-prem (your team manages it)

This deserves its own deep dive. Coming in a future post.


Putting It All Together: The Full Picture πŸ—ΊοΈ

Here's how they compare:

Type Access Use Case Analogy
ClusterIP Internal only Service-to-service calls Internal phone ext.
NodePort External via Node IP + port Dev/testing, quick access Side entrance
Ingress External via smart routing Production, multi-service Traffic cop

What's Next? πŸš€

Now that we understand how networking works inside a Kubernetes cluster, I'm deciding between two directions for the next post:

  • A hands-on walkthrough where we deploy a simple app and see Services and Ingress working in a real cluster
  • A deeper dive into traffic management covering LoadBalancers, service meshes like Istio, and how production teams actually handle external traffic

Let me know in the comments which one you'd find more useful! πŸ‘‡


Additional Resources πŸ“š

Prerequisite Reading:

Kubernetes Networking:

Services & Ingress:

Hands-On Practice:

Top comments (0)