Kubernetes Services Explained: ClusterIP, NodePort, LoadBalancer and Headless
Kubernetes services give changing Pods one stable name and address. This guide explains how selectors become endpoints, how ClusterIP, NodePort, LoadBalancer and headless types differ, how kube-proxy and CoreDNS carry traffic, and how to fix the failures you will actually meet.
Introduction
Picture an illustrative composite incident, not a named outage: a checkout API is healthy, its Pods show Running, yet every call through its Service returns connection refused. The fix was one mistyped label in a selector, which is why understanding kubernetes services starts with endpoints, not ports or load balancers.
5-minute takeaway: a Service is a stable virtual address plus a live list of ready Pod endpoints. ClusterIP serves internal traffic, NodePort opens a high port on every node, LoadBalancer adds a platform load balancer, and headless removes the virtual IP so DNS returns Pod addresses directly. If traffic fails, check endpoints first, then ports, then DNS, then node reachability, in that order.
This is lesson 9 in Module 4 of the Kubernetes roadmap, and it builds directly on the previous lesson, Kubernetes CNI explained, which covered how packets move between nodes. The CNI moves packets. Services decide which Pod a packet should reach. Keeping those two jobs separate in your head makes networking faults much faster to isolate, because a Service fault and a CNI fault produce different symptoms and need different commands.
If you are new to the wider vocabulary, read Kubernetes concepts explained first for the overview of Pods, Deployments and Services. This lesson assumes you can create a Deployment and read basic kubectl output, and it spends its time on the mechanics that overview only introduces: selectors, EndpointSlices, kube-proxy rules, DNS names, traffic policies and the edge cases that break production traffic.
1. How Kubernetes Services Turn Pod IPs Into Stable Endpoints
Kubernetes services exist because Pod IPs are temporary, while callers need an address that survives restarts, rescheduling and scaling. A Service provides that address by matching Pod labels with a selector, tracking only ready Pods as endpoints, and letting kube-proxy forward each new connection to one healthy backend.
The selector is the contract. When you writeselector: {app: checkout} on a Service, you are telling Kubernetes to find Pods in the same namespace carrying that exact label. The EndpointSlice controller watches those Pods and writes their IPs, ports and readiness into EndpointSlice objects labelled kubernetes.io/service-name=<service>. kube-proxy and CoreDNS read those slices. Nothing in this chain validates that your selector matches anything, so a typo creates a perfectly valid Service that routes nowhere.
Readiness is the gate. A Pod that is Running but failing its readiness probe is left out of the endpoints on purpose, because sending traffic to a Pod that cannot serve it helps nobody. That design is correct, and it is also why "the Pod is up but the Service is dead" is usually a readiness or selector problem rather than a networking mystery. Check kubectl get pods -l app=checkout and look at the READY column before you touch anything else.
EndpointSlice replaced the older Endpoints API as the source of truth, and the Endpoints API is deprecated from Kubernetes 1.33 onward. The practical habit to build is simple: when a Service misbehaves, read its EndpointSlices first. They tell you exactly which Pod IPs the data plane believes are backends right now, including whether each endpoint is serving, terminating, or ready but not serving during rollouts.
Here is a minimal ClusterIP Service you can adapt. Note the named targetPort: it refers to a container port name in the Pod spec, which survives port number changes better than a hard-coded number.
Two details in that manifest cause most early confusion. The port is what clients connect to on the Service address. The targetPort is the port on the Pod where your container actually listens. They do not need to match, and in production they often do not, because clients expect port 80 or 443 while containers listen on 8080 or 3000. Mixing them up gives you endpoints that look healthy and connections that are refused, which we return to in the troubleshooting section.
2. Kubernetes Services Ports: port, targetPort and Named Ports
Kubernetes services expose ports in two steps, and separating those steps prevents a whole class of faults. Clients connect to the Service port on the virtual IP, kube-proxy rewrites the destination to a Pod IP, and the packet arrives at the targetPort where your container process must be listening on all interfaces.
A named targetPort resolves through the Pod spec. If the Service says targetPort: http and the container declares ports: [{name: http, containerPort: 8080}], traffic lands on 8080. Rename the container port without updating the Service and the endpoint port cannot resolve, so name your ports once and treat the name as an API between the workload and the Service. This is also why copying a Service manifest between applications without checking container ports is a reliable way to break a working deployment.
Protocol matters more than people expect. The default is TCP. UDP Services exist for DNS, syslog and some game or telemetry traffic, and SCTP is available where the platform supports it. A Service port with the wrong protocol accepts the manifest and silently drops the traffic you cared about, because the kernel rules were programmed for a different protocol than your client sends. When a UDP workload "works on TCP", check the protocol field before blaming the network.
Multi-port Services are normal for databases and message brokers that expose a client port plus a metrics or admin port. Each entry needs a unique name, and clients select behaviour by port, not by Service. Keep admin ports on ClusterIP even when the client port is exposed externally. Splitting one workload into two Services, one internal and one external, is often cleaner than exposing every port through one LoadBalancer.
One more habit worth forming: bind your application to 0.0.0.0 inside the container, not 127.0.0.1. A process listening only on loopback looks healthy in local tests and refuses every Service connection, because kube-proxy delivers packets to the Pod IP, not to loopback. kubectl exec plus a listening-socket check settles this in seconds and saves a long afternoon of blaming kube-proxy for an application bind address.
3. ClusterIP Kubernetes Services for Internal Traffic
ClusterIP is the default type for kubernetes services, and it is the right choice for almost all internal communication. It allocates a virtual IP reachable only inside the cluster, pairs it with a DNS name, and balances new connections across ready endpoints without exposing anything to outside networks.
Use ClusterIP for service-to-service calls, internal APIs, caches, queues and databases that only cluster workloads should reach. It is also the backend type behind most Ingress and Gateway API setups: the gateway terminates external HTTP traffic and forwards to ClusterIP Services, which keeps your application Services off the public network entirely. If only Pods call it, ClusterIP is the answer, and reaching for anything else adds exposure you then have to defend.
The virtual IP is not owned by any network interface. It exists as kernel rules on every node, programmed by kube-proxy from the Service and EndpointSlice state. That is why you cannot ping a ClusterIP reliably and why curl from a node shell can behave differently from curl inside a Pod. Test Services from inside a Pod in the cluster, ideally in the same namespace as the real client, so DNS search domains and network policies match production conditions.
ClusterIP has two useful variations. You can request a specific address with clusterIP when an integration truly needs a fixed IP, although DNS names are almost always the better contract. You can also create a Service with no selector and manage EndpointSlices yourself, which is how you point a stable in-cluster name at endpoints outside the selector model, such as a fixed set of external IPs. Manual endpoints put freshness on you: nothing removes a dead backend unless your automation does.
Security note for platform teams: ClusterIP means not reachable from outside the cluster network, not automatically safe inside it. Any Pod can call any ClusterIP unless NetworkPolicy restricts it. Treat ClusterIP as the default exposure and NetworkPolicy as the access control, and you will avoid the common mistake of assuming internal means trusted.
4. NodePort Kubernetes Services and the 30000-32767 Range
NodePort kubernetes services add one behaviour to ClusterIP: the same port, chosen from the 30000-32767 range by default, opens on every node. External clients connect to any node IP plus that port, and kube-proxy forwards the connection to a ready endpoint, possibly on a different node.
NodePort still has a ClusterIP underneath, so in-cluster clients keep using the normal DNS name and port. The node port is an additional door, not a replacement. That stacking is worth remembering in interviews and in incidents: changing a Service from ClusterIP to NodePort does not move internal traffic, it only adds external reachability on a high port that your firewall, cloud security groups and node network must actually allow.
Reach for NodePort when something outside the cluster must connect and no load balancer exists: a test cluster, a lab, bare metal with an external HAProxy or F5 you manage yourself, or a quick debug path. Avoid it as the public face of a production application. Clients must know a node IP, node loss becomes client-visible, and asking users to connect to port 31000 is a sign the platform layer is missing. On managed cloud clusters, LoadBalancer or a gateway in front of ClusterIP is the production answer.
Two operational traps show up repeatedly. First, the node port range is cluster-wide and finite, so pinning a specific nodePort without checking collisions fails at apply time or surprises the next team. Let Kubernetes allocate unless an external system truly needs a fixed port. Second, NodePort traffic arriving at a node with no local endpoint is forwarded onward by default, which hides source IPs and adds a hop. The traffic policy section explains when to change that with externalTrafficPolicy.
Bare-metal clusters deserve a fair mention here. Without a cloud provider, NodePort plus your own load balancer is a legitimate, simple architecture, and many on-prem platforms run exactly that for years. The discipline is to put health checks on the external balancer against every node, so a dead node stops receiving traffic instead of black-holing a share of it.
5. LoadBalancer Kubernetes Services on Cloud and Bare Metal
LoadBalancer kubernetes services build on NodePort by asking the platform for an external load balancer with a stable address on the real Service port. On cloud clusters the provider provisions it automatically, while bare metal needs an implementation such as MetalLB before the external IP ever appears.
The stacking matters for debugging. A LoadBalancer Service has a ClusterIP, a node port and an external address, and traffic flows external balancer to node port to kube-proxy to Pod. When external traffic fails but in-cluster calls work, the fault sits in the outer layers: cloud health checks, security groups, the balancer target registration, or the node port path. When in-cluster calls also fail, go back to endpoints and targetPort. Layered thinking beats random restarts.
Cost and sprawl are the usual production complaints. Each LoadBalancer Service tends to create its own cloud balancer, so ten public Services can mean ten balancers to pay for and secure. For HTTP workloads, one gateway or Ingress controller behind a single LoadBalancer, fronting many ClusterIP Services, is cheaper and gives you hostname routing and TLS termination in one place. That routing decision is covered in Ingress vs Gateway API vs Service Mesh; this lesson only needs you to know the Service layer underneath it.
Provider annotations control balancer flavour, internal versus internet-facing placement, TLS behaviour and health check settings, and they differ between AWS, GCP and Azure. Treat annotations as provider-specific configuration, not portable YAML. The portable parts are the Service type, ports, selector and traffic policy. Keep provider annotations in an overlay per environment so the same base manifest works in a local cluster, where the LoadBalancer simply stays pending without an implementation.
Health checking has one Service-level knob worth knowing: healthCheckNodePort is allocated when externalTrafficPolicy is Local, giving the cloud balancer a node port that reports whether that node has a local ready endpoint. That is how a balancer avoids sending traffic to nodes that would drop it under Local policy. If you set Local and external checks start failing, inspect that health port before assuming the application broke.
6. Headless Kubernetes Services for Direct Pod DNS
Headless kubernetes services set clusterIP to None, which removes the virtual IP and the load balancing that comes with it. DNS then returns the individual Pod IPs behind the Service, so clients and peers can address specific Pods directly instead of asking the platform to choose one.
Headless is the right tool when Pod identity matters: database replicas, message brokers, consensus clusters and any StatefulSet whose members must find each other by name. The StatefulSet names the headless Service inserviceName, and each Pod gains a stable DNS record shaped like <pod>.<service>.<namespace>.svc.cluster.local, for example db-1.db.shop.svc.cluster.local. The name survives rescheduling even though the Pod IP changes, which is the entire point. The workload side of that pairing is covered in Deployment vs StatefulSet vs DaemonSet.
Two settings decide whether headless DNS helps or misleads. By default, DNS publishes only ready Pods, which breaks cluster formation when members must discover peers before anyone is ready. publishNotReadyAddresses: true publishes Pod addresses as soon as they exist, so seed nodes can find each other during bootstrap. Use it on the peer-discovery Service, and keep client traffic on a separate readiness-gated Service so application clients never receive addresses for Pods that cannot serve yet.
That two-Service pattern is the production shape to remember: one headless Service for member-to-member identity and discovery, one normal ClusterIP Service for load-balanced client connections. A single headless Service used for clients gives you DNS round-robin at best, no connection-level balancing, and clients that cache DNS answers will pin themselves to one Pod long after it should have drained.
The serviceName must match the headless Service name exactly, in the same namespace. A typo produces Pods with no per-Pod DNS and no error, which is a miserable fault to chase. Verify with an nslookup from a temporary Pod against both the Service name and one Pod name, and confirm the Service name returns multiple addresses while the Pod name returns exactly one.
7. ExternalName Kubernetes Services and Their Limits
ExternalName kubernetes services map an in-cluster DNS name to an external DNS name by returning a CNAME record, with no ClusterIP, no selector and no proxying. They give workloads a stable internal alias for an outside dependency, while traffic still flows directly to the external target.
The clean use case is configuration stability. Your application connects to payments-db.shop.svc.cluster.local, and platform teams can repoint the ExternalName target from a legacy host to a managed database endpoint without rebuilding images or editing every client. It is also a tidy way to give a cross-namespace Service a local alias, by pointing ExternalName at the real Service FQDN in the other namespace.
Now the caveats, because ExternalName is the type most often used for jobs it cannot do. It does not proxy, so there is no port translation in practice: clients resolve the external name and connect to the external port themselves, which means the Service port is mostly documentation. It does not health-check the target. It cannot point at a raw IP address, only a DNS name. And TLS verification happens against the external name your client ultimately resolves, so certificates must be valid for that name, not for your internal alias, unless your client is configured to verify against the alias explicitly.
Host headers and SNI follow the same logic. Because nothing rewrites the connection, HTTP clients that send the internal alias as Host can confuse virtual-host routing at the far end. Test the full request, not just DNS resolution, before declaring an ExternalName migration done. If you need port mapping, health checks or header control, you need a real proxy or a selectorless Service with managed endpoints, not ExternalName.
Used within its limits, ExternalName is still valuable. It keeps environment-specific hostnames out of application config, makes dependency moves a one-line platform change, and documents external dependencies in the same place as internal ones. Just document the limits next to it in your platform runbook so the next engineer does not expect load balancing from a DNS alias.
8. How Kubernetes Services Use kube-proxy Modes
Kubernetes services rely on kube-proxy to turn a virtual IP into kernel forwarding rules on every node. kube-proxy watches Services and EndpointSlices, then programs iptables, IPVS or nftables so packets addressed to the ClusterIP and port are rewritten to a chosen Pod IP and targetPort.
The key mental correction: kube-proxy does not sit in the packet path forwarding traffic through a userspace process. It is a controller that writes rules; the kernel does the forwarding with destination NAT. That is why a dead kube-proxy does not instantly break existing Services on a node, since the old rules remain, but it does stop new Services and endpoint changes from being reflected. Stale endpoints on one node, while other nodes behave, points at kube-proxy or its replacement on that node.
In iptables mode, chains match the ClusterIP and port, then select a backend with declining-probability rules before DNAT to the Pod. It is the long-standing default and works well, but rule walks grow with Service and endpoint counts. IPVS mode uses a kernel load balancer with hash lookups and scheduler choices, historically favoured at large scale, though current guidance deprecates IPVS in favour of newer paths. nftables mode dispatches through a verdict map and is the modern direction on supported kernels. For most teams the mode is a platform decision made by the cluster installer, not an application choice.
Some CNIs replace kube-proxy entirely. Cilium with kube-proxy replacement, for example, implements Service handling in eBPF and can make load-balancing decisions earlier in the packet path. The Service API and EndpointSlice contract stay the same, which is why your manifests do not change, but your debugging commands do: iptables listings will not show rules that were never written. Know which data plane your cluster runs before you debug it, which is exactly why the CNI lesson comes before this one in the roadmap.
Session affinity and traffic policies are implemented inside these same rules. When you set sessionAffinity to ClientIP, the backend selection stops being random per connection and pins a source IP to one endpoint for a timeout window. When you change externalTrafficPolicy, the rules change which endpoints are eligible for external traffic. The next sections cover the DNS half and the policy half of that behaviour.
9. Kubernetes Services DNS Names With CoreDNS
Kubernetes services get predictable DNS names from CoreDNS, which watches Services and EndpointSlices and answers cluster queries from its in-memory view. A normal Service resolves to its ClusterIP, a headless Service resolves to ready Pod IPs, and short names work because Pod search domains complete them.
The full form is<service>.<namespace>.svc.cluster.local. Inside the same namespace, checkout is enough. Across namespaces, checkout.shop works, and the full form works from anywhere in the cluster. CoreDNS also publishes SRV records per named port, shaped like http.tcp.checkout.shop.svc.cluster.local, which some clients and service discovery libraries use to learn port numbers from DNS instead of configuration.
The kubelet writes the CoreDNS Service IP into every Pod resolv.conf, along with search domains and options ndots:5. That ndots setting is the famous footgun: any name with fewer than five dots is tried against each search suffix before it is queried as-is. External lookups therefore cost several NXDOMAIN round trips first, and a name that accidentally matches a search-suffixed cluster name can resolve somewhere surprising. For latency-sensitive external calls, using fully qualified names with a trailing dot avoids the search walk entirely.
DNS reflects readiness, just like EndpointSlices. A Pod failing readiness disappears from headless DNS answers and from endpoint lists together, so "DNS returns nothing" for a headless Service usually means no ready Pods, not a CoreDNS fault. For a normal Service, DNS returns the ClusterIP even with zero endpoints, because the name maps to the virtual IP, not to Pods. That split is a useful diagnostic: name resolves but connection refused suggests endpoints or ports, while name does not resolve suggests CoreDNS, search domains or a wrong namespace in the name.
When name resolution itself is broken, debug from a Pod, not from your laptop. Check resolv.conf, query the full Service FQDN, query a known external name, and inspect CoreDNS Pods and logs in kube-system. Deeper packet-level faults belong with container networking troubleshooting, but most DNS incidents end at a wrong namespace, a dead CoreDNS replica set, or an application caching a stale answer beyond its TTL.
10. Kubernetes Services Traffic Policies: externalTrafficPolicy and Affinity
Kubernetes services route external traffic under two policies that trade source IP visibility against load spread, plus an affinity setting that pins clients to one Pod. Choosing them deliberately prevents the classic surprise where every backend log shows node IPs instead of real client addresses.
externalTrafficPolicy: Cluster is the default for NodePort and LoadBalancer Services. Traffic arriving at any node can be forwarded to any ready endpoint in the cluster, which spreads load evenly but usually applies source NAT, so the Pod sees a node IP rather than the client IP. externalTrafficPolicy: Local forwards only to endpoints on the receiving node. That preserves the client source IP and avoids the extra hop, but nodes without a local endpoint drop external traffic, and load becomes uneven when Pods are not spread evenly across nodes.
Pick Local when the application truly needs the real client IP for rate limiting, allow lists, audit logs or geo decisions, and pair it with topology spread so endpoints exist on the nodes that receive traffic. Pick Cluster when even distribution matters more and client IP can be recovered another way, such as PROXY protocol or forwarded headers at a gateway. There is no free option here; you are choosing which failure mode you prefer.
sessionAffinity: ClientIP pins connections from one source IP to one endpoint for a configurable timeout, defaulting to three hours. It helps legacy stateful sessions that cannot move between Pods, and it hurts when many clients share one NAT address, because they all pin to the same backend. It also interacts badly with Cluster policy, where source NAT collapses clients into node IPs before affinity sees them. If you need stickiness for real external clients, combine Local policy with affinity, or better, put stickiness at the gateway where cookies and headers are visible.
internalTrafficPolicy: Local exists for node-local patterns such as agents that should only receive traffic from Pods on the same node. It drops in-cluster traffic on nodes without a local endpoint, so pair it with a DaemonSet or do not use it. Most application Services should leave internal policy at the default and let topology preferences, where supported, express softer same-zone routing goals.
11. Choosing Kubernetes Services: Type Decision Table
Choosing kubernetes services well means matching exposure to the caller, not copying the last manifest you saw. Start from who connects, from where, and whether Pod identity matters, then pick the smallest type that satisfies that caller without adding public surface you must defend.
| Caller and need | Service type | Why it fits | Watch out for |
|---|---|---|---|
| Other Pods in the cluster | ClusterIP | Internal only, stable DNS name, balanced across ready Pods | Any Pod can call it unless NetworkPolicy restricts access |
| External clients on cloud | LoadBalancer | Platform balancer on the real port with health checks | One balancer per Service adds cost and sprawl |
| Many HTTP apps, one entry point | ClusterIP behind a gateway | One external balancer, hostname and path routing at the gateway | Gateway becomes a shared dependency to operate well |
| External access, no balancer available | NodePort | Works on any node IP without cloud integration | High port, client-visible node loss, firewall rules on every node |
| Bare metal with your own balancer | NodePort | Your balancer health-checks nodes and spreads traffic | You own balancer availability and node health checks |
| StatefulSet peers and per-Pod identity | Headless plus ClusterIP | Headless gives stable per-Pod DNS, ClusterIP balances clients | Headless alone gives clients no real load balancing |
| Stable alias for an external dependency | ExternalName | One-line repointing without client changes | No proxying, no health checks, TLS name caveats |
| Fixed endpoints outside the selector model | Selectorless ClusterIP | Stable name over endpoints you manage | You own endpoint freshness and removal of dead backends |
Read the table from the top and stop at the first row that matches your caller. Most production estates settle into a simple shape: ClusterIP for nearly everything, one gateway LoadBalancer for HTTP entry, a small number of direct LoadBalancer Services for non-HTTP protocols, headless pairs for stateful systems, and NodePort reserved for labs and bare-metal edges. If your estate looks different, it should be because a requirement forced it, not because a tutorial defaulted to NodePort.
One interview-grade distinction to keep ready: Service types stack rather than replace. NodePort includes ClusterIP behaviour, LoadBalancer includes NodePort behaviour, and headless is ClusterIP with the virtual IP removed. Saying that clearly, then naming the traffic policy trade-off, answers most Service questions at senior level.
12. Troubleshooting Kubernetes Services When Traffic Fails
Troubleshooting kubernetes services works fastest when you follow the request path in order instead of guessing. Confirm endpoints exist, confirm the targetPort matches the listening process, confirm DNS returns what you expect, then test external reachability layer by layer from a Pod inside the cluster.
| Symptom | Likely cause | Confirm with | Fix |
|---|---|---|---|
| Endpoints empty, Pods Running and Ready | Selector labels do not match Pod labels, or Service is in another namespace | Compare Service selector with Pod labels using kubectl get pods --show-labels | Patch the selector or move the Service into the Pod namespace |
| Endpoints empty, Pods Running but 0/1 Ready | Readiness probe failing, so Pods are excluded on purpose | kubectl describe pod and read the readiness events | Fix the probe path, port or application health endpoint |
| Endpoints exist, connection refused | targetPort does not match the container listening port, or app binds 127.0.0.1 | Check Service ports against the listening socket inside the Pod | Set targetPort to the real port and bind 0.0.0.0 |
| Name does not resolve | Wrong namespace in the name, CoreDNS down, or search domain confusion | nslookup the full FQDN from a test Pod and check resolv.conf | Use the full FQDN, restore CoreDNS, fix client DNS config |
| Headless name returns no addresses | No ready Pods, or serviceName does not match the headless Service | nslookup the Service name and one Pod name, compare serviceName | Fix readiness, correct serviceName, consider publishNotReadyAddresses for peers |
| NodePort unreachable from outside | Firewall or security group blocks 30000-32767, or client uses a dead node IP | Test the node port from another host and from a Pod, check node health | Open the range to intended sources, put a health-checked balancer in front |
| LoadBalancer stuck pending | No cloud integration or bare-metal balancer implementation | kubectl describe service and read events for provisioning errors | Install or fix the provider integration, such as MetalLB on bare metal |
| Backend logs show node IPs, not client IPs | externalTrafficPolicy Cluster applies source NAT | Check the Service traffic policy and test from an external client | Use Local policy with even Pod spread, or recover IP at the gateway |
| One Pod receives most traffic | ClientIP affinity, DNS caching on headless, or long-lived connections | Check sessionAffinity and whether clients reuse connections | Remove affinity, use ClusterIP for clients, add client-side balancing for gRPC |
Work the matrix top to bottom and change one thing at a time. The two empty-endpoints rows account for most Service incidents, and both are visible in under a minute with EndpointSlice output. Keep kubectl commands for these checks close at hand, because fast, boring verification beats clever guessing during an incident.
A note on connection behaviour that saves real debugging time: Services balance new connections, not individual requests. A long-lived HTTP keep-alive or gRPC connection stays on the Pod it first reached, so one busy Pod beside idle ones can be client behaviour rather than a Service fault. Check connection counts per Pod before changing Service settings, and use client-side load balancing or a mesh data plane when per-request spread truly matters.
Final checklist before you ship a Service:
- Selector matches Pod labels exactly, in the same namespace, verified with EndpointSlices showing ready addresses.
- port and targetPort are correct, named ports match the Pod spec, and the application listens on 0.0.0.0.
- Readiness probe reflects real serving ability, so endpoints only contain Pods that can answer.
- Type matches the caller: ClusterIP by default, LoadBalancer or gateway for public traffic, NodePort only with a reason.
- Headless Services pair with a ClusterIP for clients, and publishNotReadyAddresses is set only where peer discovery needs it.
- externalTrafficPolicy and sessionAffinity were chosen deliberately, with client IP needs stated in the change request.
- DNS verified from a Pod using the full FQDN, including one cross-namespace lookup if clients live elsewhere.
- NetworkPolicy allows the intended callers and blocks the rest, instead of relying on ClusterIP obscurity.
Next in this module, the roadmap continues to Gateway API, where GatewayClass, Gateway and HTTPRoute build managed entry points on top of the Service mechanics from this lesson. Follow the sequence from Module 4 on the Kubernetes roadmap so the gateway concepts land on solid ground.
Frequently Asked Questions
What are Kubernetes services and why do Pods need them?
Kubernetes services give a set of Pods one stable virtual IP and DNS name, because Pod IPs change whenever Pods restart or move. A Service selector tracks ready Pods as endpoints, and kube-proxy forwards each new connection to one healthy backend, so clients keep one address while Pods change underneath.
What is the difference between ClusterIP, NodePort and LoadBalancer in Kubernetes services?
ClusterIP is reachable only inside the cluster. NodePort adds the same high port, from 30000-32767 by default, on every node for external access. LoadBalancer adds a platform load balancer with a stable external address on the real Service port. Each type includes the behaviour of the one below it.
When should Kubernetes services be headless instead of ClusterIP?
Use a headless Service when clients or peers must address individual Pods, typically StatefulSet members such as database replicas. Setting clusterIP to None makes DNS return Pod IPs directly and gives each StatefulSet Pod a stable name. Pair it with a normal ClusterIP Service for load-balanced client traffic.
Why do Kubernetes services show no endpoints?
Empty endpoints mean the selector matched no Pods, or no matching Pod is Ready. Compare the Service selector with Pod labels in the same namespace, then check readiness probe events. Kubernetes never validates that a selector matches anything, so one mistyped label creates a Service that routes nowhere.
How do Kubernetes services resolve DNS names with CoreDNS?
CoreDNS watches Services and EndpointSlices and answers names shaped like service.namespace.svc.cluster.local. A normal Service returns its ClusterIP, while a headless Service returns ready Pod IPs. Short names work because each Pod resolv.conf lists search domains, with ndots set to 5 by default.
How do Kubernetes services preserve the client source IP?
Set externalTrafficPolicy to Local on NodePort or LoadBalancer Services, so traffic goes only to endpoints on the receiving node and source NAT is avoided. The trade-off is uneven load when Pods are not spread across nodes, so combine Local policy with topology spread or recover the IP at a gateway.
Can Kubernetes services expose a workload without a selector?
Yes. A Service with no selector gets no automatic endpoints, so you create EndpointSlice objects yourself pointing at the addresses you choose. This suits fixed external endpoints behind a stable in-cluster name, but your automation owns freshness, including removing dead backends that Kubernetes would otherwise handle.
Preparing for Senior Platform & SRE Interviews
Practice real-world cluster triage, RBAC debugging, and pod scheduling scenarios in our Kubernetes scenario interview questions hub.
Explore Interview Scenarios →