Sitemap
Kayathiri

Kayathiri

Kubernetes Learning — Day 4 : Services & Networking

3 min readJan 29, 2026

--

In the previous days, we learned about Pods and Deployments.
Today, we solve one of the most important Kubernetes problems:

Pods are not reliable network endpoints.

Pods can restart, reschedule, or scale — and every time they do, their IP changes.
So Kubernetes introduces Services to give applications a stable way to communicate.

What is a Kubernetes Service?

A Service is a Kubernetes object that provides:

  • A stable IP address
  • A stable DNS name
  • Load balancing across Pods

A Service does not run containers.
It simply routes traffic to Pods based on labels.

How Services Connect to Pods

Services work using labels and selectors.

  • Pods have labels
  • Services use selectors to find matching Pods
  • Traffic sent to the Service is distributed across those Pods

You never hardcode Pod IPs — Kubernetes handles everything.

Example Pods (Used by All Services Below)

Let’s say we have a simple app with two Pods.

apiVersion: v1
kind: Pod
metadata:
name: my-app-pod
labels:
app: myapp
spec:
containers:
- name: app-container
image: nginx
ports:
- containerPort: 80

The key part here is:

labels:
app: myapp

All Services below will use this label.

Press enter or click to view image in full size

1. ClusterIP Service (Default & Most Common)

What is ClusterIP?

  • Exposes Pods inside the cluster only
  • Cannot be accessed from outside
  • Default service type if none is specified

When to Use

  • Backend services
  • Internal APIs
  • Database access inside Kubernetes

ClusterIP YAML Example

apiVersion: v1
kind: Service
metadata:
name: myapp-clusterip
spec:
type: ClusterIP
selector:
app: myapp
ports:
- port: 80
targetPort: 80

Explanation

  • port: Port exposed by the Service
  • targetPort: Port on the Pod container
  • selector: Matches Pods with app: myapp

Pods inside the cluster can access this using:

http://myapp-clusterip

2. NodePort Service (External Access — Basic)

What is NodePort?

  • Exposes the Service on a port of every Node
  • Accessible via <NodeIP>:<NodePort>
  • Port range: 30000–32767

When to Use

  • Testing
  • Learning
  • Temporary access

❌ Not recommended for production.

NodePort YAML Example

apiVersion: v1
kind: Service
metadata:
name: myapp-nodeport
spec:
type: NodePort
selector:
app: myapp
ports:
- port: 80
targetPort: 80
nodePort: 30007

How to Access

http://<NodeIP>:30007

If you have 3 nodes, any node IP will work.

3. LoadBalancer Service (Production-Ready)

What is LoadBalancer?

  • Creates an external cloud load balancer
  • Automatically assigns a public IP
  • Supported by cloud providers (AWS, Azure, GCP)

When to Use

  • Production workloads
  • Internet-facing applications

LoadBalancer YAML Example

apiVersion: v1
kind: Service
metadata:
name: myapp-loadbalancer
spec:
type: LoadBalancer
selector:
app: myapp
ports:
- port: 80
targetPort: 80

After creation, Kubernetes provisions a cloud load balancer.

Get Kayathiri’s stories in your inbox

Join Medium for free to get updates from this writer.

Check using:

kubectl get service myapp-loadbalancer

You’ll see:

EXTERNAL-IP   34.xxx.xxx.xxx

Access your app using that IP.

4. ExternalName Service (External Dependency)

What is ExternalName?

  • Maps a Kubernetes Service to an external DNS
  • No Pods, no selectors
  • Just DNS redirection

When to Use

  • External databases
  • External APIs
  • Legacy services outside the cluster

ExternalName YAML Example

apiVersion: v1
kind: Service
metadata:
name: external-db
spec:
type: ExternalName
externalName: mydatabase.example.com

Now Pods can connect using:

external-db

Instead of remembering the real external URL.

Kubernetes DNS — Why Services Are Powerful

Kubernetes automatically creates DNS records for Services.

Format:

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

Example:

myapp-clusterip.default.svc.cluster.local

This makes microservice communication clean and reliable.

Real-World Analogy

Think of Pods as delivery drivers 🚚
They keep changing shifts and vehicles.

The Service is the company call center ☎️
Customers call one number, and calls are routed to available drivers.

Key Takeaways from Day 4

  • Pods are temporary, Services are stable
  • Services use labels to find Pods
  • ClusterIP → internal access
  • NodePort → basic external access
  • LoadBalancer → production access
  • ExternalName → external dependencies

✨ Keep following for the 45-Day Kubernetes Learning Series!

Happy Cloud Computing !!!

--

--