Skip to main content
Course/Primitives/Services β€” Stable Networking
3/860 min
Primitives

Services β€” Stable Networking

Give your Pods a stable address and load balance traffic between them.

beginner60 minRead β†’ Lab β†’ Quiz β†’ Practice
🧠 Brain Warm-Up
🧠 Brain Warm-Up: Pods are constantly dying and getting recreated with new IP addresses. If you have a backend database Pod and a frontend client Pod, how can the frontend reliably connect to the database without updating its connection config on every pod crash? Think about this networking challenge.

The Problem with Pod IPs

Pod IPs are ephemeral. Every time a Pod restarts or is rescheduled, it gets a new IP. If you hardcode a Pod IP, your app breaks after the first restart.

A Service provides:

  • A stable Virtual IP (ClusterIP) that never changes for the life of the Service.
  • A predictable DNS name: ..svc.cluster.local.
  • Load balancing across all matching Pods (via label selectors).

Service Types

TypeReachable fromUse case
ClusterIPInside cluster onlyMicroservice-to-microservice communication
NodePortOutside via NodeIP:PortDev/testing port exposure
LoadBalancerInternet via cloud LBProduction web apps

How Services Find Pods

Services use label selectors to dynamically discover their target Pods. The control plane monitors pods and updates the Service's Endpoints or EndpointSlices list.

Service selector: { app: web }
              ↓  matches
Pod labels:   { app: web, version: v2 }  βœ“ (Selected)
Pod labels:   { app: api }               βœ— (Not selected)

Kubernetes Service Traffic Routing

Client Request (curl http://web-service:80)
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             SERVICE (web-service)            β”‚
β”‚  ClusterIP: 10.96.45.100  Port: 80           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                       β”‚ (Load Balances traffic via Endpoint list)
                       β–Ό
      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
      β”‚ (kube-proxy / CNI Routing)      β”‚
      β–Ό                                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Pod (web) β”‚                     β”‚ Pod (web) β”‚
β”‚ IP: 10.244.1.3                  β”‚ IP: 10.244.2.4
β”‚ Port: 80    β”‚                   β”‚ Port: 80    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜