Nextgen Blog
HomeLearnAIQuantumRoboticsSecuritySpaceAbout
Nextgen Blog

By Anubhav — full stack engineer, IIT Mandi CSE. Deep dives into AI, software engineering, and the technologies shaping the next generation of tech.

Navigate

  • Home
  • Learn
  • Blog
  • Archive
  • About

Topics

  • Artificial Intelligence
  • Quantum Computing
  • Robotics
  • Cybersecurity
  • Space Tech

Connect

Built with ❤️ & By - Anubhav

© 2026 Nextgen Blog by Anubhav. All rights reserved.

Privacy PolicyTerms of Service
Phase 03 · Networking & ScalingChapter 12 of 33
11.
Phase 03Read time ~15 minDifficulty intermediate

Kubernetes Networking

Warrior, this is one of the most important Kubernetes chapters.

In this chapter
  • 01The Kubernetes Networking Problem
  • 02Every Pod Gets an IP
  • 03Pod IPs Are Ephemeral
  • 04Service Provides Stable Networking
  • 05Kubernetes Networking Has Multiple Layers
  • 06Container Networking
  • 07Important: localhost Is Pod-Local
  • 08Pod-to-Pod Communication
  • 09Pod-to-Pod Across Nodes
  • 10What Is CNI?
  • 11Why CNI Is Important
  • 12Service Networking
  • 13ClusterIP
  • 14Service DNS
  • 15Kubernetes DNS
  • 16Service DNS Format
  • 17NodePort
  • 18Port vs TargetPort vs NodePort
  • 19port
  • 20targetPort
  • 21nodePort
  • 22LoadBalancer
  • 23NodePort vs LoadBalancer
  • 24NodePort
  • 25LoadBalancer
  • 26What About Ingress?
  • 27Complete Request Flow
  • 28Kubernetes Networking Architecture
  • 29kube-proxy
  • 30Endpoints / EndpointSlices
  • 31Readiness and Networking
  • 32NetworkPolicy
  • 33Important: Service Is Not a Pod
  • 34Pod
  • 35Service
  • 36Service Is Not Ingress
  • 37Service
  • 38Ingress
  • 39Service Types Cheat Sheet
  • 40Practical Exercise
  • 41Test Service from Inside the Cluster
  • 42Debugging Networking
  • 43Step 1
  • 44Step 2
  • 45Step 3
  • 46Step 4
  • 47Step 5
  • 48Step 6
  • 49Common Networking Problems
  • 50Problem 1 — Service has no endpoints
  • 51Problem 2 — Wrong targetPort
  • 52Problem 3 — Application only listens on localhost
  • 53The Most Important Mental Model
  • 54Interview Questions
  • 55Q1. Does every Pod have an IP?
  • 56Q2. Are Pod IPs stable?
  • 57Q3. How do Pods communicate?
  • 58Q4. How do applications discover Services?
  • 59Q5. What is CNI?
  • 60Q6. What is ClusterIP?
  • 61Q7. Difference between port and targetPort?
  • 62Q8. What is NodePort?
  • 63Q9. What is LoadBalancer?
  • 64Q10. Why use Service instead of Pod IP?
  • 65Next → Chapter 12: Ingress
In this chapter (65 sections)
01The Kubernetes Networking Problem02Every Pod Gets an IP03Pod IPs Are Ephemeral04Service Provides Stable Networking05Kubernetes Networking Has Multiple Layers06Container Networking07Important: localhost Is Pod-Local08Pod-to-Pod Communication09Pod-to-Pod Across Nodes10What Is CNI?11Why CNI Is Important12Service Networking13ClusterIP14Service DNS15Kubernetes DNS16Service DNS Format17NodePort18Port vs TargetPort vs NodePort19port20targetPort21nodePort22LoadBalancer23NodePort vs LoadBalancer24NodePort25LoadBalancer26What About Ingress?27Complete Request Flow28Kubernetes Networking Architecture29kube-proxy30Endpoints / EndpointSlices31Readiness and Networking32NetworkPolicy33Important: Service Is Not a Pod34Pod35Service36Service Is Not Ingress37Service38Ingress39Service Types Cheat Sheet40Practical Exercise41Test Service from Inside the Cluster42Debugging Networking43Step 144Step 245Step 346Step 447Step 548Step 649Common Networking Problems50Problem 1 — Service has no endpoints51Problem 2 — Wrong targetPort52Problem 3 — Application only listens on localhost53The Most Important Mental Model54Interview Questions55Q1. Does every Pod have an IP?56Q2. Are Pod IPs stable?57Q3. How do Pods communicate?58Q4. How do applications discover Services?59Q5. What is CNI?60Q6. What is ClusterIP?61Q7. Difference between port and targetPort?62Q8. What is NodePort?63Q9. What is LoadBalancer?64Q10. Why use Service instead of Pod IP?65Next → Chapter 12: Ingress

If you understand Kubernetes networking properly, the architecture of real applications becomes much easier.

Our goal today is to understand this complete request flow:

Browser
   ↓
Internet
   ↓
Load Balancer / Ingress
   ↓
Service
   ↓
Pod
   ↓
Container

But before that, we need to understand how Pods communicate.


1. The Kubernetes Networking Problem#

Imagine we have:

Node A
└── Pod A
 
Node B
└── Pod B

Pod A needs to communicate with Pod B.

Pod A ───────────> Pod B

Kubernetes needs to provide networking between them.

The Kubernetes networking model expects that:

  1. Every Pod gets its own IP address.
  2. Pods can communicate with other Pods without requiring NAT in the normal Pod-to-Pod path.
  3. Nodes can communicate with Pods.
  4. Pod IPs are routable within the cluster networking model.

The exact implementation is handled by the cluster's networking solution.


2. Every Pod Gets an IP#

Suppose:

Pod A → 10.244.1.10
Pod B → 10.244.1.11
Pod C → 10.244.2.10

Conceptually:

              Kubernetes Cluster
 
        ┌──────────────────────────────┐
        │                              │
        │  Pod A                       │
        │  10.244.1.10                 │
        │       │                      │
        │       │                      │
        │       ▼                      │
        │  Pod B                       │
        │  10.244.1.11                 │
        │                              │
        └──────────────────────────────┘

Pods can communicate using these IPs.

But there is a problem.


3. Pod IPs Are Ephemeral#

Suppose:

Pod A
10.244.1.10

gets deleted.

Deployment creates a replacement:

New Pod A
10.244.1.25

The IP changed.

Therefore, this is a bad architecture:

Frontend
   ↓
10.244.1.10

because tomorrow that Pod might have:

10.244.1.25

This is exactly why we learned Services.


4. Service Provides Stable Networking#

Instead of:

Frontend
    ↓
Pod IP

we use:

Frontend
    ↓
Service
    ↓
Pod

For example:

backend-service

could point to:

Pod A
Pod B
Pod C

Architecture:

                   backend-service
                         │
              ┌──────────┼──────────┐
              ▼          ▼          ▼
            Pod A      Pod B      Pod C

Pods can come and go.

The Service remains stable.


5. Kubernetes Networking Has Multiple Layers#

A useful mental model:

┌─────────────────────────────┐
│        External Network     │
│         Internet            │
└──────────────┬──────────────┘
               │
          Ingress / LB
               │
┌──────────────▼──────────────┐
│       Kubernetes Network    │
│                             │
│        Service              │
│           │                 │
│           ▼                 │
│          Pods               │
│           │                 │
│       Containers            │
└─────────────────────────────┘

Let's break it down.


6. Container Networking#

Inside a Pod:

Pod
│
├── Container A
│
└── Container B

Containers in the same Pod share the Pod network namespace.

Therefore they can communicate through:

localhost

For example:

Container A
    │
    │ localhost:8080
    ▼
Container B

If Container A listens on:

8080

another container in the same Pod can potentially access:

http://localhost:8080

7. Important: localhost Is Pod-Local#

Suppose:

Pod A
├── frontend
└── sidecar

They can use:

localhost

to communicate.

But:

Pod A

cannot use:

localhost

to reach:

Pod B

because they have different network namespaces.

So:

Same Pod
    ↓
localhost

while:

Different Pods
    ↓
Pod IP / Service DNS

8. Pod-to-Pod Communication#

Suppose:

frontend Pod
10.244.1.10

and:

backend Pod
10.244.2.20

The frontend needs to call backend.

Conceptually:

Frontend Pod
10.244.1.10
      │
      │ network
      ▼
Backend Pod
10.244.2.20

Kubernetes networking handles routing between Pods, including when they are on different nodes.


9. Pod-to-Pod Across Nodes#

Imagine:

Node 1
┌──────────────────┐
│ Frontend Pod     │
│ 10.244.1.10      │
└──────────────────┘
         │
         │
         ▼
      Cluster
         │
         ▼
Node 2
┌──────────────────┐
│ Backend Pod      │
│ 10.244.2.20      │
└──────────────────┘

The Kubernetes networking implementation provides the connectivity.

The actual mechanism depends on the cluster's CNI/network plugin.


10. What Is CNI?#

CNI stands for:

Container Network Interface

CNI is a standard used for configuring networking for containers.

Kubernetes itself defines the networking model, while a CNI implementation provides the actual networking functionality.

Examples include:

Calico
Cilium
Flannel
AWS VPC CNI
Azure CNI
Google networking implementations

Different Kubernetes environments can use different networking implementations.


11. Why CNI Is Important#

Without networking:

Pod A    ❌    Pod B

With a CNI:

Pod A ─────────── Pod B

The CNI can handle things such as:

  • Pod networking
  • IP allocation
  • Routing
  • Network policy support, depending on implementation
  • Node-to-node networking

12. Service Networking#

Now let's return to Services.

Suppose:

backend-service

has:

ClusterIP = 10.96.10.50

and selects:

Pod A → 10.244.1.10
Pod B → 10.244.1.11
Pod C → 10.244.2.20

Then:

Frontend
    │
    ▼
10.96.10.50
    │
    ├──────> Pod A
    ├──────> Pod B
    └──────> Pod C

The Service provides a stable endpoint.


13. ClusterIP#

The default Service type is:

ClusterIP

Example:

apiVersion: v1
kind: Service
 
metadata:
  name: backend-service
 
spec:
  selector:
    app: backend
 
  ports:
    - port: 80
      targetPort: 3000

Kubernetes assigns a ClusterIP.

For example:

10.96.10.50

This Service is normally accessible inside the cluster.


14. Service DNS#

You don't normally want your application hardcoding:

10.96.10.50

Instead use DNS.

Inside the cluster:

backend-service

can resolve to the Service.

For cross-namespace access:

backend-service.production

And fully qualified:

backend-service.production.svc.cluster.local

15. Kubernetes DNS#

Kubernetes normally provides DNS through a cluster DNS service, commonly CoreDNS.

Conceptually:

Application
    │
    │ backend-service
    ▼
CoreDNS
    │
    ▼
Service IP
    │
    ▼
Backend Pods

So your Node.js code can do:

fetch("http://backend-service/api/users");

instead of:

fetch("http://10.96.10.50/api/users");

16. Service DNS Format#

The general fully qualified format is:

<service>.<namespace>.svc.cluster.local

Example:

backend-service.production.svc.cluster.local

Breakdown:

backend-service
       ↓
Service name
 
production
       ↓
Namespace
 
svc
       ↓
Service domain
 
cluster.local
       ↓
Cluster DNS domain

17. NodePort#

Now suppose you want access from outside the cluster.

You can use:

NodePort

Example:

apiVersion: v1
kind: Service
 
metadata:
  name: backend-service
 
spec:
  type: NodePort
 
  selector:
    app: backend
 
  ports:
    - port: 80
      targetPort: 3000
      nodePort: 30080

Now:

Client
   ↓
Node IP:30080
   ↓
Service
   ↓
Pod:3000

18. Port vs TargetPort vs NodePort#

This is a very common interview question.

Suppose:

ports:
  - port: 80
    targetPort: 3000
    nodePort: 30080

port#

80

The Service listens on this port.

targetPort#

3000

The application Pod receives traffic on this port.

nodePort#

30080

The Kubernetes nodes expose this port for NodePort access.

So:

Client
   ↓
NodeIP:30080
   ↓
Service:80
   ↓
Pod:3000

19. LoadBalancer#

In cloud Kubernetes, you commonly use:

type: LoadBalancer

Example:

apiVersion: v1
kind: Service
 
metadata:
  name: backend-service
 
spec:
  type: LoadBalancer
 
  selector:
    app: backend
 
  ports:
    - port: 80
      targetPort: 3000

A cloud provider can provision an external load balancer.

Conceptually:

Internet
   │
   ▼
Cloud Load Balancer
   │
   ▼
Kubernetes Service
   │
   ▼
Pods

20. NodePort vs LoadBalancer#

NodePort#

Internet
   ↓
Node IP:30080
   ↓
Service
   ↓
Pods

LoadBalancer#

Internet
   ↓
Cloud Load Balancer
   ↓
Service
   ↓
Pods

LoadBalancer is generally more convenient for external cloud exposure, though exact architecture varies.


21. What About Ingress?#

Here's where things become powerful.

Suppose you have:

frontend-service
backend-service
admin-service

You don't necessarily want:

frontend.example.com → separate LB
backend.example.com  → separate LB
admin.example.com    → separate LB

Instead, an Ingress can route HTTP/HTTPS traffic:

                    Internet
                       │
                       ▼
                    Ingress
                  /    |     \
                 /     |      \
                ▼      ▼       ▼
          frontend   backend   admin
           Service    Service  Service

We'll study Ingress deeply in Chapter 12.


22. Complete Request Flow#

Let's say the user opens:

https://example.com/api/users

A typical architecture could look like:

Browser
   │
   │ HTTPS
   ▼
Cloud Load Balancer
   │
   ▼
Ingress Controller
   │
   │ /api
   ▼
backend-service
   │
   ▼
Backend Pod
   │
   ▼
Node.js container

Inside Node.js:

GET /api/users

might query:

PostgreSQL Service
        │
        ▼
PostgreSQL Pod

So:

Browser
   ↓
Load Balancer
   ↓
Ingress
   ↓
Service
   ↓
Node.js Pod
   ↓
Postgres Service
   ↓
Postgres Pod
   ↓
Persistent Storage

That's a real Kubernetes application architecture.


23. Kubernetes Networking Architecture#

Put everything together:

                         INTERNET
                            │
                            ▼
                    Cloud Load Balancer
                            │
                            ▼
                     Ingress Controller
                            │
              ┌─────────────┴─────────────┐
              │                           │
              ▼                           ▼
      frontend-service             backend-service
              │                           │
        ┌─────┼─────┐               ┌─────┼─────┐
        ▼     ▼     ▼               ▼     ▼     ▼
      Pod A Pod B Pod C            Pod A Pod B Pod C
                                      │
                                      │
                                      ▼
                               postgres-service
                                      │
                                      ▼
                                PostgreSQL Pod
                                      │
                                      ▼
                                     PVC
                                      │
                                      ▼
                               Persistent Storage

This is the architecture you should start visualizing when you think "Kubernetes application."


24. kube-proxy#

You learned about kube-proxy in Chapter 3.

Now you can understand why it exists.

kube-proxy is traditionally responsible for implementing Service networking behavior on nodes, often using mechanisms such as iptables or IPVS depending on configuration.

Conceptually:

Client Pod
    │
    ▼
Service IP
    │
    ▼
Service networking rules
    │
    ▼
Backend Pod

Modern Kubernetes networking implementations can vary, and some environments use eBPF-based datapaths such as Cilium that can change how these functions are implemented.

The important beginner mental model is:

Service provides the stable abstraction; the cluster networking implementation handles how traffic reaches the selected Pods.


25. Endpoints / EndpointSlices#

Remember:

Service
   ↓
Pods

How does Kubernetes know which Pods belong to the Service?

Through the Service selector.

For example:

selector:
  app: backend

If Pods have:

labels:
  app: backend

they become Service backends.

Kubernetes represents these backend addresses using EndpointSlices.

You can inspect them:

kubectl get endpointslices

or:

kubectl get endpointslices -l kubernetes.io/service-name=backend-service

Conceptually:

Service
   │
   ▼
EndpointSlice
   │
   ├── Pod A IP
   ├── Pod B IP
   └── Pod C IP

26. Readiness and Networking#

This connects to Chapter 5.

Suppose:

Pod A → Ready
Pod B → Not Ready
Pod C → Ready

The Service should normally route traffic only to ready endpoints.

So:

Service
   │
   ├── Pod A ✅
   ├── Pod B ❌
   └── Pod C ✅

This is one reason readiness probes are so important.

Without readiness checks, Kubernetes could send traffic to an application that isn't ready to handle requests.


27. NetworkPolicy#

By default, depending on the cluster/network implementation and configuration, workloads may be able to communicate broadly.

You can introduce:

NetworkPolicy

to control allowed traffic.

For example:

frontend → backend     ✅
backend → postgres     ✅
frontend → postgres    ❌

Conceptually:

Frontend
   │
   ├──────────> Backend ✅
   │
   └──────────> Postgres ❌
 
Backend
   │
   └──────────> Postgres ✅

This is a major security topic.

We'll study it in Chapter 20.


28. Important: Service Is Not a Pod#

Don't confuse:

Pod

and:

Service

Pod#

Runs the application.

Pod
└── Container

Service#

Provides a stable networking endpoint for selected Pods.

Service
   ↓
Pods

So:

Pod = workload

Service = networking abstraction


29. Service Is Not Ingress#

Another common interview question.

Service#

Routes traffic to Pods.

Service
   ↓
Pods

Ingress#

Provides HTTP/HTTPS routing rules to Services.

Ingress
   ↓
Services
   ↓
Pods

So:

Ingress
   ↓
Service
   ↓
Pod

30. Service Types Cheat Sheet#

Type Typical purpose
ClusterIP Internal cluster communication
NodePort Expose through node port
LoadBalancer External cloud load balancer
ExternalName DNS alias to an external service

Most applications heavily use:

ClusterIP

internally.

External access is often handled by:

Ingress + Load Balancer

or another gateway/load-balancing architecture.


31. Practical Exercise#

Create a backend:

kubectl create deployment backend \
  --image=nginx

Expose it:

kubectl expose deployment backend \
  --port=80 \
  --target-port=80

Check:

kubectl get svc

You'll see something like:

NAME      TYPE        CLUSTER-IP
backend   ClusterIP   10.96.x.x

Now:

kubectl get endpointslices

You should see the backend endpoints.


32. Test Service from Inside the Cluster#

Run a temporary Pod:

kubectl run curl \
  --image=curlimages/curl \
  -it \
  --rm \
  -- sh

Inside it:

curl http://backend

The request:

curl Pod
   ↓
backend Service
   ↓
backend Pod
   ↓
nginx

This is an excellent practical exercise.


33. Debugging Networking#

When networking doesn't work, use:

Step 1#

Check Pods:

kubectl get pods -o wide

Step 2#

Check Service:

kubectl get svc

Step 3#

Check Service details:

kubectl describe svc backend

Step 4#

Check EndpointSlices:

kubectl get endpointslices

Step 5#

Test DNS:

nslookup backend

from a suitable debugging Pod.

Step 6#

Test HTTP:

curl http://backend

This gives you a basic networking troubleshooting workflow.


34. Common Networking Problems#

Problem 1 — Service has no endpoints#

You run:

kubectl get endpointslices

and discover no backend addresses.

Possible reason:

Service selector
       ≠
Pod labels

For example:

Service:

selector:
  app: backend

Pod:

labels:
  app: api

They don't match.

Therefore:

Service
   ❌
Pod

35. Problem 2 — Wrong targetPort#

Application listens on:

3000

but Service says:

targetPort: 8080

Then:

Service
   ↓
8080
   ❌
Application
   ↓
3000

Connection fails.


36. Problem 3 — Application only listens on localhost#

This is a very common Node.js/Docker issue.

Suppose your Node.js application does:

app.listen(3000, "127.0.0.1");

Inside the container, it's only listening on loopback.

Better for a containerized server:

app.listen(3000, "0.0.0.0");

or:

app.listen(3000);

depending on the framework/runtime behavior.

Why?

Because Kubernetes needs to reach the application's network interface through the Pod network.


37. The Most Important Mental Model#

Memorize this:

                INTERNET
                    │
                    ▼
             Load Balancer
                    │
                    ▼
                 Ingress
                    │
                    ▼
                Service
                    │
             ┌──────┼──────┐
             ▼      ▼      ▼
            Pod    Pod    Pod
             │
             ▼
         Container

For internal communication:

Frontend Pod
     │
     │ DNS
     ▼
backend-service
     │
     ▼
Backend Pod

For database:

Backend Pod
     │
     │ DNS
     ▼
postgres-service
     │
     ▼
PostgreSQL Pod
     │
     ▼
PVC
     │
     ▼
Persistent Storage

38. Interview Questions#

Q1. Does every Pod have an IP?#

Under the standard Kubernetes networking model, yes, each Pod gets a unique cluster IP.


Q2. Are Pod IPs stable?#

No.

Pods are ephemeral, so their IPs can change.

Use a Service for stable access.


Q3. How do Pods communicate?#

Through the cluster networking model, typically using Pod IPs or Services.


Q4. How do applications discover Services?#

Through Kubernetes DNS.

Example:

backend-service

Q5. What is CNI?#

Container Network Interface, a standard for configuring container networking. Kubernetes clusters use a CNI implementation to provide Pod networking.


Q6. What is ClusterIP?#

The stable virtual IP assigned to a Service for internal cluster access.


Q7. Difference between port and targetPort?#

port
   ↓
Service port
 
targetPort
   ↓
Application/Pod port

Example:

Service:80
   ↓
Pod:3000

Q8. What is NodePort?#

A Service type that exposes the Service through a port on each node, typically from the configured NodePort range.


Q9. What is LoadBalancer?#

A Service type that can integrate with a cloud provider to provision an external load balancer.


Q10. Why use Service instead of Pod IP?#

Because Pod IPs are ephemeral while Services provide a stable endpoint and service discovery.


🧠 Chapter 11 Cheat Sheet#

Pod
 ↓
Has IP
 ↓
IP can change
 ↓
Service
 ↓
Stable endpoint
 ↓
DNS
 ↓
Service discovery

External traffic:

Internet
   ↓
Load Balancer
   ↓
Ingress
   ↓
Service
   ↓
Pod
   ↓
Container

Internal traffic:

Pod A
  ↓
Service DNS
  ↓
Service
  ↓
Pod B

And:

Same Pod
   ↓
localhost
 
Different Pods
   ↓
Pod IP / Service
 
Different namespaces
   ↓
Service.namespace

🎯 Chapter 11 Key Takeaway#

If you remember only one diagram from this chapter, remember this:

                         USER
                          │
                          ▼
                     INTERNET
                          │
                          ▼
                  ┌───────────────┐
                  │ Load Balancer │
                  └───────┬───────┘
                          │
                          ▼
                  ┌───────────────┐
                  │    Ingress    │
                  └───────┬───────┘
                          │
                   HTTP routing
                          │
             ┌────────────┴────────────┐
             ▼                         ▼
      frontend-service          backend-service
             │                         │
        ┌────┼────┐               ┌────┼────┐
        ▼    ▼    ▼               ▼    ▼    ▼
       Pod  Pod  Pod              Pod  Pod  Pod
                                      │
                                      ▼
                              postgres-service
                                      │
                                      ▼
                                PostgreSQL Pod
                                      │
                                      ▼
                                     PVC
                                      │
                                      ▼
                              Persistent Storage

You now have the core Kubernetes architecture from application → storage → networking.

Next → Chapter 12: Ingress#

We'll go deep into:

Ingress
Ingress Controller
Host-based routing
Path-based routing
HTTP vs HTTPS
TLS certificates
Domains
Multiple Services behind one entry point

And we'll build an architecture like:

https://example.com        → Next.js
https://example.com/api    → Node.js
https://admin.example.com → Admin App

with Kubernetes YAML.

Finished this chapter?

Mark it as complete to track your mastery.

Previous ChapterChapter 10 — Volumes & Persistent StorageNext ChapterChapter 12 — Ingress
PrevNext