Day 5: Kubernetes Services — How Your App Gets a Stable IP or URL

Let’s Start With What You Might Know

By now, you’ve launched a container, wrapped it in a Pod, deployed it using a Deployment, and scaled it up to multiple Pods.

But here’s the next problem:

“Okay, my app is running inside Kubernetes… but how do I access it?”

You try running:

kubectl get pods -o wide

And you see something like:

NAME       READY   STATUS    IP            NODE
myapp-xyz  1/1     Running   10.244.1.5    worker-node-1

Great — but:

  • That Pod IP is internal
  • It changes if the Pod dies and restarts
  • And if you have 3 replicas… which IP do you even hit?

That’s where Services come in.


What Is a Kubernetes Service?

Service is a stable way to access one or more Pods.

You can think of it as:

  • permanent IP address or DNS name inside the cluster
  • load balancer that routes traffic to the right Pods
  • gateway between your app and the outside world (if needed)

How It Works

  • You attach a Service to a set of Pods using labels
  • The Service tracks the matching Pods — even as Pods come and go
  • Kubernetes uses something called kube-proxy to route traffic to the correct Pod behind the scenes

So even if Pods restart, the Service endpoint never changes.

Example

Let’s say you run 3 Pods of a web app with the label:

app: myapp

You create a Service like this:

selector:
  app: myapp

Now, when someone accesses the Service:

  • Kubernetes forwards the request to any of the healthy Pods
  • It’s automatic, balanced, and reliable

Types of Services (Simplified)

Type Use Case Accessible From
ClusterIP (default) Internal communication Inside the cluster only
NodePort Basic external access Outside the cluster (via IP:port)
LoadBalancer Cloud environments Public IP from cloud provider
ExternalName Maps to external DNS For external services

Real-World Analogy

Imagine your app’s Pods are like food trucks moving around a festival ground.

Service is like the signpost that says:

🍔 “Burgers this way →”

You don’t care where the trucks are parked — you just follow the sign. Kubernetes routes you to the right place, even if trucks come and go.

Try It Out

Use the Kubernetes Playground:
👉 KodeKloud Kubernetes Playground

Create a deployment:

kubectl create deployment myapp --image=nginx
kubectl expose deployment myapp --port=80 --type=NodePort
kubectl get service

Now run:

kubectl get pods -o wide
kubectl describe service myapp

Look for the NodePort (e.g., 30123) and try opening:

http://<worker-node-ip>:30123

You’re now accessing your app through a Kubernetes Service!

Quick Summary

  • Pods have dynamic IPs and can restart anytime
  • Service gives your app a stable endpoint
  • Services load-balance traffic to healthy Pods
  • You can expose your app internally or externally with different service types

Coming Up...

📅 Day 6: ConfigMaps & Secrets — Managing App Settings and Sensitive Data

You’ll learn:

  • Why you should never hardcode passwords or configs in containers
  • How Kubernetes separates config data and secrets
  • How to use them in real applications

New here? Start from Day 1 and catch up on the series:

Day 1: What Is Kubernetes & Why Should You Care?
Discover why Kubernetes matters and how it changes the game.

Day 2: What Are Pods in Kubernetes?
Understand the smallest deployable unit in Kubernetes.

Day 3: Understanding Nodes, Clusters & the Kubernetes Control Plane
See how all the pieces connect behind the scenes.

Day 4: Deployments & ReplicaSets — How Kubernetes Runs and Manages Your App
Learn how Kubernetes keeps your apps running smoothly.