Skip to main content

Command Palette

Search for a command to run...

Understanding Kubernetes Services: Service Discovery, Load Balancing & External Exposure

Updated
β€’3 min read

When working with Kubernetes, you quickly learn how Deployments create Pods and how replica sets ensure availability.

But production systems introduce a critical networking challenge.

Pods β€” which encapsulate containers β€” are ephemeral by nature.

And that changes everything.


πŸ” The Real Problem: Ephemeral Pods & Changing IPs

In Kubernetes:

  • Pods are temporary

  • If a Pod crashes, it is recreated

  • The recreated Pod gets:

    • A new IP address

    • A new internal identity

    • Possibly scheduled on another node

Now imagine:

  • Users connecting directly to a Pod IP

  • Another microservice depending on that IP

The moment the Pod restarts β€” the connection breaks.

Even though Kubernetes provides auto-healing, direct Pod access is unreliable in real-world environments.

This is the networking problem that Kubernetes Services solve.


🧠 What Is a Kubernetes Service?

A Service provides a stable network endpoint for a group of Pods.

Instead of accessing individual Pod IPs, clients connect to:

  • A virtual ClusterIP

  • Or a DNS name automatically created by Kubernetes

Example DNS format:

service-name.namespace.svc.cluster.local

Behind the scenes:

  • The Service selects Pods using labels

  • kube-proxy configures routing rules

  • Traffic is distributed to healthy Pods

This abstraction ensures reliability even when Pods are recreated.


βš™οΈ Core Capabilities of Kubernetes Services

1️⃣ Load Balancing

When multiple Pod replicas exist, the Service automatically distributes traffic across them.

User β†’ Service β†’ Pod A
                β†’ Pod B
                β†’ Pod C

This ensures:

  • Even traffic distribution

  • No single Pod overload

  • High availability

Traffic routing is implemented by kube-proxy, running on each node.


2️⃣ Service Discovery via Labels & Selectors πŸ”Ž

Services do not track Pods by IP address.

Instead, they use:

  • Labels (attached to Pods)

  • Selectors (defined in the Service)

Example:

Pod:

labels:
  app: payment

Service:

selector:
  app: payment

As long as a Pod carries that label, it becomes part of the Service.

Even if:

  • The Pod is deleted

  • A new Pod is created

  • The IP address changes

The Service continues routing traffic correctly.

This is automated service discovery β€” no manual IP management required.


🌍 Types of Kubernetes Services

According to official Kubernetes documentation, there are multiple service types. The three most commonly used in production are:


1️⃣ ClusterIP (Default)

  • Default Service type

  • Exposes the application only inside the cluster

  • Provides a stable internal IP

πŸ”Ή Best used for:

  • Microservice-to-microservice communication

  • Backend APIs

  • Databases

ClusterIP is the safest and most commonly used option.


2️⃣ NodePort

https://miro.medium.com/v2/resize%3Afit%3A1200/1%2Au_PWTqKyKTEe-7gRUa6bUA.png

  • Exposes the Service on each node’s IP

  • Uses a static port (default range: 30000–32767)

Accessible via:

<NodeIP>:<NodePort>

πŸ”Ή Suitable for:

  • Internal testing

  • Organizational network access

  • Non-production environments


3️⃣ LoadBalancer ☁️

https://cdn.sanity.io/images/6icyfeiq/production/28c8e4297864fb721ca9d94d5491fd3d53039f15-1286x746.png?auto=format&fit=max&h=552&q=75&w=952

  • Used in cloud environments

  • Automatically provisions an external load balancer

  • Assigns a public IP

Supported by cloud providers like:

  • Amazon Web Services

  • Microsoft Azure

  • Google Cloud Platform

Traffic flow:

Internet β†’ Cloud Load Balancer β†’ Service β†’ Pods

Ideal for production, internet-facing applications.


🧩 Behind the Scenes: How It Works

kube-proxy

  • Runs on every worker node

  • Maintains network rules

  • Ensures Service IP forwards traffic to correct Pods

DNS Resolution

Kubernetes provides internal DNS.

Services are discoverable using:

service-name.namespace.svc.cluster.local

This eliminates IP dependency entirely.


🎯 Key Takeaways

  • Pods are ephemeral β€” their IP addresses change

  • Services provide a stable network abstraction

  • Labels and selectors power dynamic service discovery

  • Load balancing happens automatically

  • Service type determines exposure level

Without Services, Kubernetes networking would be fragile and unreliable.

With Services, it becomes production-grade and scalable.

More from this blog

codeops-labs.hashnode.dev

16 posts