Video Overview
This note explains:
- Why Kubernetes Services are needed
- Problems with direct Pod communication
- Types of Services (VERY IMPORTANT)
- Real-world traffic flow
π Backbone of Kubernetes Networking
β Concept 1: Problem Without Services
Warning
Pods are NOT reliable for direct communication
π« Issues:
- π Pod IPs keep changing (ephemeral) :contentReference[oaicite:0]{index=0}
- β No stable endpoint
- βοΈ No load balancing
- π No external access
π§ Example Problem:
- Frontend pod β Backend pod
- Needs hardcoded IP β
- Pod restarts β IP changes β broken communication
β Concept 2: What is a Kubernetes Service?
Important
Quote
Service = Stable IP + DNS + Load Balancer for Pods
π― What it Provides:
- π Stable IP
- π DNS name
- βοΈ Load balancing
- π Service discovery
π How It Works
Example
User β Service β Pod
Pod β Service β Pod
π§ Key Idea:
- Pods are dynamic
- Services are stable
π¦ Concept 3: Types of Kubernetes Services
Important
- ClusterIP
- NodePort
- LoadBalancer
- ExternalName
π’ 1. ClusterIP (DEFAULT)
Success
Internal communication inside cluster
π§ Definition:
- Exposes service inside cluster only
- NOT accessible externally
π Use Case:
- Frontend β Backend communication
π Analogy:
- Office extension number βοΈ
- Internal calls only
βοΈ YAML Example
apiVersion: v1
kind: Service
metadata:
name: backend-svc
spec:
type: ClusterIP
selector:
app: backend
ports:
- protocol: TCP
port: 9090
targetPort: 5678π§ Flow:
Pod β DNS (CoreDNS) β Service IP β Pod
π Key Points:
- Stable DNS:
backend-svc - Load balances across pods
- Uses selectors
π‘ 2. NodePort
Important
Exposes service outside cluster
π§ Definition:
- Opens a port on every node
- Range:
30000β32767
π Analogy:
- Building front desk βοΈ
βοΈ YAML
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 31000π Access:
NodeIP:NodePort
π Flow:
User β NodeIP:NodePort β ClusterIP β Pod
β οΈ Key Points:
- Built on top of ClusterIP
- Need node IPs
- Not ideal for production
π΅ 3. LoadBalancer
Success
Production-ready external access (Cloud)
π§ Definition:
- Creates external load balancer
- Provides public IP
π Analogy:
- Call center βοΈ
π Flow:
User β LoadBalancer β NodePort β ClusterIP β Pod
β οΈ Important:
- Works in cloud (AWS, Azure, GCP)
- Not available in local clusters (like kind)
π§ Reality Check
Warning
Rarely used directly in production
Why?
- No advanced routing
- No host-based routing
π Instead use:
- Ingress Controller
π£ 4. ExternalName
Info
Connects to external services
π§ Definition:
- Maps service β external DNS
βοΈ YAML
apiVersion: v1
kind: Service
metadata:
name: db-svc
spec:
type: ExternalName
externalName: mydb.amazonaws.comπ Flow:
Pod β Service β External DB
π§ Use Case:
- Connect to:
- RDS
- External APIs
- Third-party services
π‘ Why use it?
Important
- Avoid hardcoding external URLs
- Easy to update endpoints
- Decouples configuration
π₯ Concept 4: Selectors & Endpoints
Important
π― Selector:
selector:
app: backend- Matches pods with label
π Endpoints:
- Actual pod IPs behind service
π§ Key Idea:
Quote
Service β Selector β Pods
π§ Concept 5: Ports Explained
| Field | Meaning |
|---|---|
| port | Service port |
| targetPort | Container port |
| nodePort | External access port |
π§ Concept 6: DNS Resolution
Info
- Handled by CoreDNS
- Converts:
backend-svc β ClusterIP
π§ Final Flow (IMPORTANT)
Example
Frontend Pod β backend-svc β Backend Pod
β οΈ Key Observations
Warning
- Pods are ephemeral
- Services are stable
- NodePort = dev/testing
- LoadBalancer = cloud
- ClusterIP = internal
π§ Final Takeaways
Summary
- Service = stable networking layer
- Enables:
- Communication
- Load balancing
- Service discovery
- Core for microservices
π One-Line Summary
Quote
Pods change β Services stay constant βΈοΈ