DEV Community

Shiva Charan
Shiva Charan

Posted on

🌐 Kubernetes Service Types (4 Types)

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:

  1. ClusterIP (default)
  2. NodePort
  3. LoadBalancer
  4. 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
Enter fullscreen mode Exit fullscreen mode

🟧 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
Enter fullscreen mode Exit fullscreen mode

βœ” Where it can be accessed from:

  • Outside the cluster
  • Inside the cluster
  • From any node

Example:

Your node IP is:

192.168.10.5
Enter fullscreen mode Exit fullscreen mode

If NodePort = 32000:

http://192.168.10.5:32000
Enter fullscreen mode Exit fullscreen mode

Example YAML:

type: NodePort
nodePort: 32000
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

βœ” Where it can be accessed from:

  • Public internet
  • External apps
  • Perfect for production

Requires:

  • AWS, GCP, Azure, DigitalOcean, etc.

Example YAML:

type: LoadBalancer
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

DNS returns:

pod-1-ip
pod-2-ip
pod-3-ip
Enter fullscreen mode Exit fullscreen mode

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)