Kubernetes Learning — Day 4 : Services & Networking
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: 80The key part here is:
labels:
app: myappAll Services below will use this label.
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: 80Explanation
port: Port exposed by the ServicetargetPort: Port on the Pod containerselector: Matches Pods withapp: myapp
Pods inside the cluster can access this using:
http://myapp-clusterip2. 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: 30007How to Access
http://<NodeIP>:30007If 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: 80After 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-loadbalancerYou’ll see:
EXTERNAL-IP 34.xxx.xxx.xxxAccess 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.comNow Pods can connect using:
external-dbInstead 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.localExample:
myapp-clusterip.default.svc.cluster.localThis 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 !!!







