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

  1. ClusterIP
  2. NodePort
  3. LoadBalancer
  4. 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

FieldMeaning
portService port
targetPortContainer port
nodePortExternal 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 ☸️