Day 25 - Kubernetes Services
Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
๐ Why Do We Need a Service in Kubernetes?
In real production environments:
We donโt deploy pods directly.
We deploy deployments, which internally create a ReplicaSet, which finally creates pods.
Assume we have a deployment with 3 pods (replicas).
These replicas are required because:
One pod cannot handle many concurrent users.
For example: if 1 pod handles 10 users and you have 100 users โ you need ~10 pods.
โ ๏ธ Problem: What if There Is No Service in Kubernetes?
Pods get dynamic IP addresses.
Example:
Pod 1 โ 172.16.3.4
Pod 2 โ 172.16.3.5
Pod 3 โ 172.16.3.6
If a pod crashes, Kubernetes auto-heals and creates a new pod โ new IP address.
Example:
Pod 1 dies
New Pod 1 โ 172.16.3.8 (IP changed)
Now the users/testers/other internal teams who were using 172.16.3.4 cannot access the application anymore.
So even though Kubernetes healed the pod correctly โ application becomes unreachable due to changed IP.
This is the core reason Kubernetes Services are required.
๐ฆ How a Service Solves This Problem
Instead of giving direct pod IPs to users, DevOps creates a Service on top of the Deployment.
Users will now access the application using:
payment.default.svc
The service:
Acts as a load balancer
Performs service discovery
Can expose applications externally
1๏ธโฃ Load Balancing
The service receives traffic and distributes it across all pods.
Example:
10 requests โ Pod1
10 requests โ Pod2
10 requests โ Pod3
So all pods handle load evenly.
2๏ธโฃ Service Discovery (VERY IMPORTANT)
A service does NOT track pod IPs.
Instead, it uses:
โ๏ธ Labels
โ๏ธ Selectors
Example label on pods:
app: payment
If pods die and new ones are created:
IP address changes
Label remains the same
Service always finds the correct pods because it filters by labels.
This solves the problem of constantly changing IPs.
3๏ธโฃ Exposing Applications Externally
Services can expose your app inside or outside the cluster depending on the service type.
There are 3 main service types:
๐น Type 1 โ ClusterIP (default)
Application accessible only inside the Kubernetes cluster
Provides load balancing + service discovery
Not accessible from outside
๐น Type 2 โ NodePort
Application accessible inside your organization / VPC
Anyone who can reach Worker Node IP can access the app
Useful for internal company apps
๐น Type 3 โ LoadBalancer
Application accessible from the internet (publicly)
Creates a Cloud Load Balancer (ELB on AWS)
Best for apps like:
Any public website
Note:
LoadBalancer works only on cloud providers (AWS, GCP, Azure)
Does NOT work by default on Minikube (needs addons/metallb)
๐ Example Summary (From Your Content)
| Service Type | Who Can Access | Purpose |
| ClusterIP | Only inside Kubernetes | Internal services |
| NodePort | Anyone with access to Node IP | Internal org access |
| LoadBalancer | Anyone on the internet | Public access |
๐ง Final Summary of Your Content
Kubernetes Services provide:
โ๏ธ Load Balancing
โ๏ธ Service Discovery (through labels & selectors)
โ๏ธ External Exposure (depending on type)
Without a Service:
Pods get new IPs when recreated
Users cannot access the application
Auto-healing breaks connectivity
With a Service:
Users access via a single stable address
Traffic is distributed
IP changes of pods donโt matter