Services: ClusterIP, NodePort and LoadBalancer

Intermediate · 3 min

A stable virtual IP in front of changing Pods: how Service types build on each other, how cluster IPs are allocated, and the traffic policies that matter.

Before thisThe Kubernetes network model and CNILabels, selectors, annotations and namespaces

Mischa van den Burg · 10 min · from 6:38

Services: ClusterIP, NodePort and LoadBalancer

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Mischa van den BurgReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A Service gives a label-selected set of Pods one stable virtual IP and DNS name. The IP isn't on any interface. Each node's proxy rewrites traffic to it into a real Pod IP.
  • The types stack: NodePort is a ClusterIP plus a port (30000-32767) on every node, and LoadBalancer is a NodePort plus an external load balancer that a cloud controller or MetalLB provides.
  • Cluster IPs come from ServiceCIDR objects and each one is recorded as an IPAddress object. Dynamic allocation avoids the low band of the range so static IPs you pick don't collide.
  • externalTrafficPolicy Local keeps the client's source IP and skips the extra hop, but only nodes with a ready local Pod receive traffic, checked through a healthCheckNodePort.
  • Headless Services (clusterIP None) skip the virtual IP and return Pod IPs from DNS. ExternalName is only a DNS CNAME to an outside name, with no proxying.

Pod IPs are the wrong thing to depend on

The network model gives every Pod an IP. Every Pod is also disposable. A Deployment replaces Pods on every rollout, every node drain, every crash. Each replacement gets a new IP. A frontend that kept a list of backend Pod IPs would be wrong within the hour.

What clients want is a name and an address that stay put while the Pods behind them come and go. That’s a Service: a stable virtual IP and DNS name in front of whichever Pods currently match a label selector. Think of a company’s support phone number. It never changes, and whoever is on shift answers it.

The basic Service

apiVersion: v1
kind: Service
metadata: {name: web, namespace: shop}
spec:
  selector: {app: web}
  ports:
  - {name: http, port: 80, targetPort: 8080}

selector picks the Pods. port is what clients use on the Service. targetPort is where the Pods listen, and it can be a named container port such as http, so Pods can change port numbers without the Service changing. The control plane tracks which matching Pods are ready in EndpointSlices, the subject of the next lesson.

Applying it on our lab cluster gave it 10.96.241.29. That address doesn’t belong to any machine. No interface has it, and no Pod has it. On every node, kube-proxy (or an eBPF replacement) programs rules that catch packets to 10.96.241.29:80 and rewrite them to a ready Pod’s ip:8080. That’s why curl to a cluster IP works and ping usually doesn’t: the rules only match the Service’s ports.

Where cluster IPs come from

Cluster IPs come from the service range, which is now an API object. Since 1.33 a ServiceCIDR holds the range and each allocated address is an IPAddress object that names its Service:

$ kubectl get servicecidrs
NAME         CIDRS          AGE
kubernetes   10.96.0.0/16   12m
$ kubectl get ipaddresses
NAME            PARENTREF
10.96.0.1       services/default/kubernetes
10.96.173.110   services/shop/web-np
10.96.241.29    services/shop/web
10.96.81.26     services/shop/web-lb

A cluster that runs out of service IPs can now add a range with another ServiceCIDR instead of restarting every API server with a new flag. We added 10.100.0.0/24 that way.

You may also choose the IP with spec.clusterIP, for something like a DNS server that needs a well-known address. To make that safe, dynamic allocation avoids a low band of each range: 1/16th of it, at least 16 and at most 256 addresses, per calculateRangeOffset in the allocator. For a /16 that’s 10.96.0.0 to 10.96.0.255, reserved in practice for addresses you pick by hand. All three dynamic IPs above landed well above it. Once set, the IP is fixed: patching it failed with may not change once set.

The types stack

ClusterIP is the default and only reachable inside the cluster.

NodePort adds a port, from 30000 to 32767 by default, opened on every node. Traffic to any node’s IP on that port reaches the Service. Ours got 80:30733. Asking for 29000 was refused: provided port is not in the valid range. It’s how you get traffic in without a cloud, and it’s the plumbing under the next type.

LoadBalancer adds an external load balancer that forwards to the node ports (or straight to Pod IPs, on some clouds):

spec:
  type: LoadBalancer
  externalTrafficPolicy: Local
  selector: {app: web}
  ports:
  - {name: http, port: 80, targetPort: http}

The Service object only asks. A controller has to deliver: the cloud controller manager on AWS, GCP or Azure, or MetalLB or a vendor controller on bare metal. Our lab has none, so EXTERNAL-IP stayed <pending>, which is exactly what you see on a cluster without one. loadBalancerClass chooses between several LB controllers, and cloud-specific behaviour (internal or external, which LB product) is set with annotations.

Each type is a superset of the one before. A LoadBalancer Service has a cluster IP and node ports too, unless you turn the node ports off with allocateLoadBalancerNodePorts: false where the LB can reach Pods directly.

Traffic policies

Arriving at a node isn’t the same as arriving at a Pod on that node. By default (externalTrafficPolicy: Cluster), a node forwards external traffic to any ready Pod in the cluster, possibly on another node, and SNATs it so the reply comes back the same way. The app then sees a node IP, not the client’s.

externalTrafficPolicy: Local delivers only to Pods on the receiving node, with no SNAT, so the client IP survives and there’s no second hop. Nodes without a ready local Pod would drop the traffic, so the Service gets a healthCheckNodePort (ours was 31646) that load balancers probe to skip those nodes. The trade-off is balance: a node with one Pod gets the same share as a node with five.

Inside the cluster, internalTrafficPolicy: Local keeps traffic on the client’s node, useful for node-local agents. trafficDistribution is a softer hint: PreferSameZone (GA since 1.35, the clearer name for PreferClose) and PreferSameNode keep traffic local when a local endpoint exists and fall back otherwise, which cuts cross-zone data charges. sessionAffinity: ClientIP pins a client to one Pod.

Two Services without a virtual IP

A headless Service sets clusterIP: None. There’s no virtual IP and no proxying. DNS for the Service returns the ready Pods’ IPs directly, and with a StatefulSet each Pod also gets its own stable name. Clients that need a particular member, such as a database replica or a peer in a cluster, use this.

An ExternalName Service is only a DNS alias: payments-api.shop becomes a CNAME for api.payments.example.com. Nothing proxies, ports are ignored, and HTTPS clients will send the external hostname in SNI and expect its certificate. It’s a convenient seam for moving a dependency in or out of the cluster later.

About the video

The embed is a 10-minute clip, 6:38 to 16:45, of Mischa van den Burg’s “Kubernetes Networking Explained” from May 2025. The clip’s chapters cover why Services exist, why Pods are ephemeral while Services are stable, ClusterIP against NodePort against LoadBalancer, and how Services connect to cloud infrastructure. The video’s earlier chapters, on Pod networking and CNI, overlap the previous lesson. It doesn’t cover headless or ExternalName Services, traffic policies or IP allocation, which this lesson adds from the lab and docs. Judged from chapters, since transcripts can’t be fetched here, and from its “English (US) original” audio track. Nana’s 2020 video in deeper is longer and covers headless Services and multi-port Services.

What was run: against a local v1.37.3 API server whose nodes run no containers, we created the ClusterIP, NodePort, LoadBalancer, headless and ExternalName Services above, listed the ServiceCIDR and IPAddress objects, added a second ServiceCIDR, and hit the node-port range and immutable-IP errors. The LoadBalancer stayed pending because no cloud controller runs. No traffic flowed, since there’s no kube-proxy or CNI. Proxying, SNAT and traffic-policy behaviour are from the Kubernetes docs and the allocator band from bitmap.go in the v1.37.3 source, checked 2026-11-28.

Where this fits

A Service is a selector and a virtual IP. Something has to turn those into real Pod addresses and packet rules on every node. Next: EndpointSlices and kube-proxy.

Check yourself

  1. 01You can curl a Service's cluster IP on port 80 from a Pod, but ping to the same IP fails. Is the Service broken?

    No. The cluster IP is virtual: kube-proxy's rules only match the Service's protocol and ports, and no interface owns the address. ICMP to it usually goes nowhere. Test with the real port.

  2. 02Your LoadBalancer Service stays at EXTERNAL-IP <pending> forever on a bare-metal cluster. Why?

    The Service API only records the request. A controller has to provision the load balancer and write status.loadBalancer: the cloud controller manager on a cloud, or something like MetalLB or a vendor LB controller on bare metal. Without one, nothing fills it in.

  3. 03Your app logs show every client as a node IP, not the real client. Which setting changes that, and what is the cost?

    externalTrafficPolicy Local. Traffic is only delivered to Pods on the node that received it, so no SNAT is needed and the source IP survives. The cost is uneven load if Pods aren't spread evenly, and nodes without a ready Pod fail the health check and get no traffic.

  4. 04Why does a StatefulSet usually come with a headless Service?

    Clients of a database often need a specific member, not a random one. A headless Service gives each Pod a stable DNS name (pod-0.svc.ns.svc.cluster.local) resolving to that Pod's IP, and returns all member IPs for the Service name, with no virtual IP in between.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark