What is a Kubernetes Service?

· Category: Kubernetes

Short answer

A Kubernetes Service exposes a set of Pods as a network service. It provides a stable IP and DNS name, load balances traffic across healthy Pods, and supports different exposure types like ClusterIP, NodePort, and LoadBalancer.

How it works

Services use selectors to match Pods by labels. The kube-proxy component on each node maintains routing rules to forward traffic to the backend Pods. Endpoints track the current set of healthy Pod IPs.

Example

apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 8080
  type: ClusterIP

Why it matters

Because Pods are ephemeral, their IP addresses change on restart. Services provide a stable abstraction layer for inter-service communication, external access, and load balancing.

Key differences

  • ClusterIP: Internal cluster access only.
  • NodePort: Exposes the service on each node's IP at a static port.
  • LoadBalancer: Provisions an external load balancer in cloud environments.
  • ExternalName: Maps to an external DNS name.