Kubernetes Services provide stable networking for Pods.
Pods die β new Pods come β new IPs.
Service gives a stable IP + DNS name.
There are 4 main types:
- ClusterIP (default)
- NodePort
- LoadBalancer
- Headless Service
π¦ 1. ClusterIP (Default Service)
β What is it?
- A ClusterIP service exposes your application inside the cluster only.
- It gets a virtual IP that only Kubernetes nodes and Pods can access.
β Where it can be accessed:
- From inside the cluster (Pods)
- From other microservices
β Not accessible from outside the cluster.
Example use cases:
- Internal microservices
- Databases
- Internal APIs
Example YAML:
type: ClusterIP
π§ 2. NodePort
β What is it?
Exposes the Service on every Nodeβs IP, using a port between 30000β32767.
Traffic Flow:
User β NodeIP:NodePort β ClusterIP β Pods
β Where it can be accessed from:
- Outside the cluster
- Inside the cluster
- From any node
Example:
Your node IP is:
192.168.10.5
If NodePort = 32000:
http://192.168.10.5:32000
Example YAML:
type: NodePort
nodePort: 32000
Use cases:
- Simple external access
- Development/testing
- Quick demo environments
π© 3. LoadBalancer
β What is it?
Creates a cloud provider Load Balancer (AWS ELB/NLB, Azure LB, GCP LB)
which routes traffic to your Pods.
Traffic Flow:
User β Cloud Load Balancer β NodePort β ClusterIP β Pods
β Where it can be accessed from:
- Public internet
- External apps
- Perfect for production
Requires:
- AWS, GCP, Azure, DigitalOcean, etc.
Example YAML:
type: LoadBalancer
Use cases:
- Exposing web applications
- Frontend services
- APIs for customers
πͺ 4. Headless Service (No ClusterIP)
β What is it?
A Service without a cluster IP.
Why?
So that Kubernetes does NOT load-balance traffic.
Instead, DNS returns all Pod IPs.
Configuration:
clusterIP: None
DNS returns:
pod-1-ip
pod-2-ip
pod-3-ip
Used for:
- Stateful applications
- Databases (MySQL, Cassandra, MongoDB)
- Apps that need to talk directly to each Pod
- StatefulSets
Use case example:
A database cluster needs direct Pod-to-Pod communication.
π― Quick Visual Summary
| Service Type | Accessible From | Purpose |
|---|---|---|
| ClusterIP | Inside cluster only | Internal services |
| NodePort | Outside cluster via NodeIP:Port | Simple external access |
| LoadBalancer | Internet/public | Production-grade external access |
| Headless | DNS β Pod IPs | Stateful sets, direct Pod access |
π§ One-Line Definitions (Interview Ready)
- ClusterIP: Internal service for communication inside the cluster.
- NodePort: Exposes service on every nodeβs IP using a fixed port.
- LoadBalancer: Creates a cloud load balancer to expose service externally.
- Headless Service: No cluster IP; DNS gives individual Pod IPs for direct access.
Top comments (0)