Home KubernetesKubernetes Services Explained: ClusterIP, NodePort, and LoadBalancer

Kubernetes Services Explained: ClusterIP, NodePort, and LoadBalancer

by Knowledge Base Linux
Kubernetes Services Explained — Kubernetes Services Explained: ClusterIP, NodePort, and LoadBalancer

This article covers Kubernetes Services Explained in detail. Pods in Kubernetes are temporary: they crash, get rescheduled, and receive new IP addresses every time they are replaced. If other applications connected to pod IPs directly, everything would break within hours. The object that solves this is the Service. Choosing between Kubernetes services ClusterIP NodePort LoadBalancer types is one of the first real design decisions you make on a cluster, and each type exposes your application to a different audience. This guide explains how Kubernetes services ClusterIP NodePort LoadBalancer work, when to use each one, and how to create them with practical YAML examples.

Why Kubernetes Services Exist – Kubernetes Services Explained

A Service gives a group of pods one stable virtual IP and one DNS name. Under the hood, the Service watches a label selector, keeps a list of healthy pod IPs (the Endpoints), and load-balances traffic between them. Your application connects to my-service and Kubernetes figures out which pod actually receives the request. If you are new to the building blocks, our guide to the Kubernetes Deployment and ReplicaSet explains how the pods behind a service are managed.

kubectl get endpoints my-service   # see which pod IPs are behind a service

ClusterIP: The Default Kubernetes Services ClusterIP NodePort LoadBalancer Starting Point – Kubernetes Services Explained

ClusterIP is the default type. The Service receives an internal IP that is reachable only from inside the cluster. This is the right choice for databases, internal APIs, and any backend that other in-cluster applications consume.

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

Other pods now reach the application at http://web (or http://web.production.svc.cluster.local across namespaces). Nothing is exposed to the internet, which makes ClusterIP the safest and most common type — most production services are ClusterIP services fronted by an Ingress.

https://kblinux.com/wp-content/uploads/2026/10/media-generation-k8s-service-types-0-a4163414-0461-4f2a-a369-35ca293035a1.webp

NodePort: Exposing a Service on Every Node

NodePort builds on ClusterIP and additionally opens a static port (from the 30000–32767 range) on every node in the cluster. Anyone who can reach any node’s IP can use that port to reach your application:

apiVersion: v1
kind: Service
metadata:
  name: web-nodeport
spec:
  type: NodePort
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30080

Now http://<any-node-ip>:30080 serves your app. NodePort is handy for development clusters, demos, and bare-metal setups without a load balancer, but the high random-looking port and the lack of a single clean entry point make it a poor fit for public production traffic on its own.

LoadBalancer: The Cloud-Native Front Door

LoadBalancer builds on NodePort and asks the cloud provider (AWS, Google Cloud, Azure, or a bare-metal implementation such as MetalLB) to provision a real external load balancer in front of the nodes. The Service receives a public IP or hostname:

apiVersion: v1
kind: Service
metadata:
  name: web-lb
spec:
  type: LoadBalancer
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 80
kubectl get svc web-lb
NAME     TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)
web-lb   LoadBalancer   10.96.120.44   203.0.113.15    80:31234/TCP

This is the standard way to publish an application on a managed cluster. The downside is cost and granularity: every LoadBalancer Service typically creates its own cloud load balancer, and it only understands Layer 4 (TCP/UDP). For HTTP routing by hostname or path, you combine ClusterIP services with an Ingress instead.

Kubernetes Services ClusterIP NodePort LoadBalancer: Headless Services

A fourth, special option deserves a mention. Setting clusterIP: None creates a headless Service: no virtual IP is assigned, and DNS returns the individual pod IPs. Stateful applications such as databases use headless services together with StatefulSets so that clients can address each pod individually (for example mysql-0.mysql).

Choosing Between Kubernetes Services ClusterIP NodePort LoadBalancer

  • Internal-only traffic (APIs, databases, microservices): ClusterIP.
  • Quick external access on a dev or bare-metal cluster: NodePort.
  • Public production app on a cloud cluster: LoadBalancer — one per application.
  • Many HTTP apps sharing one public IP: ClusterIP services plus an Ingress controller.
  • Stateful workloads needing per-pod DNS: headless Service.

Troubleshooting Service Connectivity

  • Service has no endpoints: the selector does not match any pod labels. Compare kubectl get pods --show-labels with the Service’s selector.
  • Connection refused inside the cluster: the targetPort does not match the port the container actually listens on.
  • LoadBalancer stuck in <pending>: no cloud controller or MetalLB is configured to fulfil it — normal on local clusters such as kind or Minikube (Minikube has a tunnel command for this).
  • DNS does not resolve: check the CoreDNS pods in the kube-system namespace, and remember cross-namespace names need the namespace suffix. Our kubectl commands cheat sheet lists the describe and endpoints commands that expose these problems fastest.

Conclusion

The three main Kubernetes services ClusterIP NodePort LoadBalancer types form a ladder: ClusterIP for internal communication, NodePort to open a port on every node, and LoadBalancer to bring in a real external load balancer. Most real systems mix them — ClusterIP everywhere internally, and a LoadBalancer or Ingress at the edge. Once you understand that ladder, exposing any workload becomes a two-minute decision instead of guesswork. For full details on session affinity, external traffic policy, and dual-stack networking, see the official Kubernetes Service documentation.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.