12 Kubernetes Service Patterns Explained with Use Cases

Kubernetes Services explained: ClusterIP, NodePort, LoadBalancer, ExternalName, headless and 7 traffic patterns, each with a use case and YAML.

Dec 30, 2025 - 12:29
Nov 11, 2026 - 03:36
 0  204
TOPICAdvanced DevOpsPractical guide
12 Kubernetes Service Patterns Explained with Use Cases

A Kubernetes Service gives a changing set of pods one stable name and virtual IP. There are four Service types (ClusterIP, NodePort, LoadBalancer and ExternalName), plus headless Services and several traffic settings. This guide explains twelve Service patterns built from those pieces, each with a real use case and a working manifest.

Fields and defaults were checked against the Kubernetes v1.37 documentation in November 2026, including the deprecation of the Endpoints API and the newer trafficDistribution values.

Key takeaways

  • ClusterIP is the default and covers most internal traffic. Reach for NodePort or LoadBalancer only when clients outside the cluster need access.
  • A headless Service (clusterIP: None) returns pod IPs directly from DNS. StatefulSets use it to give each pod a stable DNS name.
  • ExternalName works only at the DNS level, so HTTP Host headers and TLS certificates may not match. A selector-less Service with an EndpointSlice is often a better way to reach external systems.
  • externalTrafficPolicy: Local keeps the client source IP; internalTrafficPolicy: Local keeps traffic on the same node; trafficDistribution: PreferSameZone prefers endpoints in the client's zone.
  • The Endpoints API is deprecated since v1.33. Use EndpointSlices when you read or write backend lists.
  • Services are layer 4. For HTTP host and path routing use Gateway API or an Ingress controller in front of them.

How a Service works

Pods come and go, and each new pod gets a new IP. A Service selects pods by label and keeps a list of the ready ones in EndpointSlices. kube-proxy (or a CNI that replaces it, such as Cilium) programs each node so that traffic to the Service's virtual IP and port is sent to one of those pods. CoreDNS publishes the Service as name.namespace.svc.cluster.local.

Three port fields appear in almost every manifest:

  • port: the port clients use on the Service.
  • targetPort: the port the container listens on. It defaults to the same value as port, and can be a named container port.
  • nodePort: for NodePort and LoadBalancer Services, the port opened on every node. The default range is 30000-32767, set by the API server flag --service-node-port-range.

For where Services sit among the other cluster parts, see Kubernetes architecture components.

The twelve patterns at a glance

#PatternKey settingReachable fromTypical use case
1ClusterIPtype: ClusterIPInside the clusterInternal APIs, databases
2NodePorttype: NodePortNode IP and portLabs, on-prem with external LB
3LoadBalancertype: LoadBalancerExternal LB addressPublic TCP or UDP services
4Internal LoadBalancerProvider annotationPrivate network (VPC)Access from other VPC workloads
5ExternalNametype: ExternalNameCluster DNS aliasManaged database hostname
6HeadlessclusterIP: NonePod IPs via DNSClient-side load balancing, gRPC
7Headless + StatefulSetserviceNamePer-pod DNS namesKafka, Cassandra, PostgreSQL replicas
8Selector-less + EndpointSliceNo selectorInside the clusterLegacy VM or on-prem backend
9Preserve client IPexternalTrafficPolicy: LocalExternalRate limiting, geo rules, logs
10Node-local trafficinternalTrafficPolicy: LocalSame node onlyDaemonSet agents
11Zone-aware routingtrafficDistribution: PreferSameZoneInside the clusterLower latency and cross-zone cost
12Session affinitysessionAffinity: ClientIPAnyApps with in-memory sessions

1. ClusterIP: internal service-to-service traffic

ClusterIP is the default type. Kubernetes assigns a virtual IP reachable only from inside the cluster. Use it for anything that only other workloads call: internal REST or gRPC APIs, caches, message brokers and databases.

apiVersion: v1
kind: Service
metadata:
  name: orders
  namespace: shop
spec:
  selector:
    app.kubernetes.io/name: orders
  ports:
    - name: http
      port: 80
      targetPort: 8080

Other pods call http://orders.shop or the full name orders.shop.svc.cluster.local. To test from your laptop without exposing it, use kubectl port-forward svc/orders 8080:80 -n shop.

2. NodePort: simple external access

A NodePort Service opens the same port on every node and forwards it to the Service. It builds on ClusterIP, so the internal IP still exists.

spec:
  type: NodePort
  selector:
    app.kubernetes.io/name: web
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 30080

Use case: local clusters (kind, minikube), training labs, and on-premises setups where a hardware load balancer or HAProxy already sends traffic to node IPs. Avoid exposing NodePorts directly to the internet: clients must know node IPs, nodes change, and the high port range is awkward for users. Leave nodePort unset unless you need a fixed value, and Kubernetes will pick a free one.

3. LoadBalancer: public services on a cloud

A LoadBalancer Service asks the cloud provider (or an on-prem implementation such as MetalLB) to create an external load balancer that sends traffic to the Service. It builds on NodePort.

spec:
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: game-server
  ports:
    - protocol: UDP
      port: 7777
      targetPort: 7777

Use case: non-HTTP protocols that need a public endpoint, such as game servers, MQTT brokers or custom TCP services. For many HTTP services, one Gateway or Ingress controller behind one load balancer is cheaper than a load balancer per Service. The .spec.loadBalancerIP field has been deprecated since v1.24; use your provider's annotation to request a specific address. Our review of Kubernetes load balancers compares implementations.

4. Internal LoadBalancer: private access across a VPC

Most cloud providers can create a private load balancer that has an address only inside your virtual network. The switch is an annotation, and each provider uses its own.

metadata:
  name: reporting-api
  annotations:
    # Azure AKS example; AWS and GKE use their own annotations
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
spec:
  type: LoadBalancer

Use case: a service that VMs, other clusters or on-prem systems in the same private network must reach, but the internet must not. On AWS, the AWS Load Balancer Controller uses service.beta.kubernetes.io/aws-load-balancer-scheme: internal; on GKE the annotation is networking.gke.io/load-balancer-type: "Internal". Check your provider's current docs, because annotations vary by controller version.

5. ExternalName: a DNS alias for something outside

An ExternalName Service has no selector and no cluster IP. Cluster DNS answers lookups for it with a CNAME record pointing to another hostname.

apiVersion: v1
kind: Service
metadata:
  name: billing-db
  namespace: shop
spec:
  type: ExternalName
  externalName: billing.abc123.ap-south-1.rds.amazonaws.com

Use case: applications connect to billing-db, and you can change the real hostname later (for example during a database migration) without changing app config. The Kubernetes docs list caveats: redirection happens only in DNS, so HTTP requests carry a Host header the target may not recognise, and TLS servers cannot present a certificate for the alias name. The externalName field must be a DNS name, not an IP address. It works well for databases and other TCP protocols, and poorly for HTTPS.

6. Headless Service: direct pod IPs

Setting clusterIP: None creates a headless Service. There is no virtual IP and no kube-proxy load balancing. A DNS lookup returns the IP of every ready pod.

spec:
  clusterIP: None
  selector:
    app.kubernetes.io/name: grpc-backend
  ports:
    - port: 50051

Use case: gRPC clients that keep long-lived HTTP/2 connections. With a normal ClusterIP, one connection sticks to one pod and load spreads badly. With a headless Service, the client resolves all pod IPs and balances requests itself. Service meshes and some databases' client drivers rely on the same idea.

7. Headless Service with a StatefulSet: stable per-pod names

When a StatefulSet's serviceName points to a headless Service, each pod gets its own DNS record: pod-name.service-name.namespace.svc.cluster.local. The name stays the same when the pod is rescheduled.

apiVersion: v1
kind: Service
metadata:
  name: kafka
spec:
  clusterIP: None
  selector:
    app.kubernetes.io/name: kafka
  ports:
    - name: broker
      port: 9092
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kafka
spec:
  serviceName: kafka
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: kafka
  template:
    metadata:
      labels:
        app.kubernetes.io/name: kafka
    spec:
      containers:
        - name: kafka
          image: apache/kafka:3.9.0
          ports:
            - containerPort: 9092

Use case: clustered systems where members must address each other individually: Kafka brokers (kafka-0.kafka, kafka-1.kafka), Cassandra seeds, Elasticsearch masters or a PostgreSQL primary and replicas. Add a second, normal ClusterIP Service if clients should also have a single load-balanced entry point. Storage for these pods is covered in Kubernetes storage options explained.

8. Service without a selector plus an EndpointSlice

If you omit the selector, Kubernetes creates no backends automatically. You add them yourself with an EndpointSlice that points to IP addresses outside the cluster.

apiVersion: v1
kind: Service
metadata:
  name: legacy-erp
spec:
  ports:
    - name: https
      port: 443
      targetPort: 8443
---
apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
  name: legacy-erp-1
  labels:
    kubernetes.io/service-name: legacy-erp
addressType: IPv4
ports:
  - name: https
    port: 8443
endpoints:
  - addresses:
      - "10.20.30.40"

Use case: a system that still runs on a VM or in a data centre, which you plan to move into the cluster later. Pods call legacy-erp today, and when the workload moves, you add a selector and delete the manual slice. Unlike ExternalName, this works with IP addresses and keeps the Service's virtual IP. Use EndpointSlice rather than the older Endpoints object, which has been deprecated since v1.33.

9. externalTrafficPolicy: Local to keep the client IP

With the default externalTrafficPolicy: Cluster, a node that receives external traffic may forward it to a pod on another node, and the pod sees the node's IP as the source because the packet was SNATed. Setting Local sends traffic only to pods on the receiving node and preserves the client source IP.

spec:
  type: LoadBalancer
  externalTrafficPolicy: Local

Use case: rate limiting, IP allow lists, geo rules and accurate access logs. The trade-off: nodes without a ready pod fail the load balancer health check (Kubernetes allocates a healthCheckNodePort for this), and load can be uneven if pods are not spread evenly. Use topology spread constraints to balance pods across nodes.

10. internalTrafficPolicy: Local for node agents

internalTrafficPolicy: Local tells kube-proxy to route in-cluster traffic only to endpoints on the same node as the client. If the node has no ready endpoint, traffic is dropped rather than sent elsewhere.

spec:
  selector:
    app.kubernetes.io/name: otel-agent
  internalTrafficPolicy: Local
  ports:
    - name: otlp-grpc
      port: 4317

Use case: a DaemonSet such as an OpenTelemetry collector, a log shipper or a node-local cache. Application pods send telemetry to the agent on their own node, which avoids cross-node traffic and keeps per-node data where it belongs. Our article on Kubernetes logging tools covers common agents.

11. trafficDistribution: zone-aware routing

In multi-zone clusters, traffic that crosses zones adds latency and, on most clouds, data transfer charges. The .spec.trafficDistribution field expresses a preference. In Kubernetes v1.37, the documented values are PreferSameZone, PreferSameNode and the deprecated alias PreferClose. If the field is not set, the implementation uses its default routing.

spec:
  selector:
    app.kubernetes.io/name: catalog
  trafficDistribution: PreferSameZone
  ports:
    - port: 80
      targetPort: 8080

Use case: a read-heavy catalog or pricing service with replicas in every zone. Callers reach the copy in their own zone when one is ready and fall back to other zones otherwise. Make sure each zone has enough replicas; a preference concentrates load, so an under-provisioned zone can overload. Support depends on your kube-proxy or CNI implementation and cluster version, so confirm before relying on it.

12. Session affinity: sticky clients

By default, each new connection can go to any ready pod. sessionAffinity: ClientIP sends connections from the same client IP to the same pod for a timeout period.

spec:
  sessionAffinity: ClientIP
  sessionAffinityConfig:
    clientIP:
      timeoutSeconds: 3600

Use case: an older application that keeps user sessions in memory and cannot share them yet. It is a stopgap. Many clients behind one NAT will all land on one pod, and the session is lost when that pod restarts. Moving session state to Redis or a database is the better long-term fix.

Beyond Services: Ingress and Gateway API

Services route by IP and port. They do not look at HTTP hostnames, paths or headers, and they do not terminate TLS. For that, put a layer 7 component in front:

  • Gateway API is the newer Kubernetes standard, with Gateway, HTTPRoute, GRPCRoute and other resources, and a clear split between cluster operators and app teams.
  • Ingress is the older, simpler API. It is still supported, but the popular Ingress NGINX controller was retired in March 2026, and the Kubernetes project recommends Gateway API or another controller.

Both send traffic to ClusterIP Services, so everything above still applies. See Kubernetes gateways for API traffic for controller options.

Choosing the right pattern

If you need to...Use
Call a service from other podsClusterIP
Expose HTTP or HTTPS publiclyGateway API or Ingress in front of ClusterIP
Expose TCP or UDP publiclyLoadBalancer
Reach a service only from the private networkInternal LoadBalancer
Alias a managed database hostnameExternalName
Point to fixed external IPsSelector-less Service + EndpointSlice
Address each replica of a stateful systemHeadless + StatefulSet
Keep the real client IPexternalTrafficPolicy: Local
Talk to the agent on the same nodeinternalTrafficPolicy: Local
Cut cross-zone traffictrafficDistribution: PreferSameZone

Troubleshooting Services

Most Service problems come down to labels, ports or readiness. Work through these checks in order:

# 1. Does the Service exist, and what are its ports?
kubectl get svc orders -n shop -o wide

# 2. Does it have ready backends?
kubectl get endpointslices -n shop -l kubernetes.io/service-name=orders

# 3. Do the pod labels match the selector?
kubectl get pods -n shop -l app.kubernetes.io/name=orders --show-labels

# 4. Does DNS resolve from inside the cluster?
kubectl run dns-test -n shop --rm -it --image=busybox:1.36 --restart=Never -- nslookup orders

# 5. Is the app listening on targetPort?
kubectl exec -n shop deploy/orders -- netstat -tln

An empty EndpointSlice usually means the selector does not match pod labels or the pods are failing readiness probes. Connections refused usually mean targetPort does not match the container port. If a NetworkPolicy is in place, check that it allows the traffic; Kubernetes network policies explains the common patterns. For more practice, try our Kubernetes scenario-based interview questions.

Practise Kubernetes networking

Services, DNS and network policies are core topics in the CKA and CKAD exams. Our CKA training and CKAD training cover them in hands-on labs, at the Kharadi, Pune classroom and live online.

Frequently asked questions

What are the types of Kubernetes Services?

There are four: ClusterIP (the default, internal only), NodePort (a port on every node), LoadBalancer (an external load balancer) and ExternalName (a DNS alias). A headless Service is a ClusterIP Service with clusterIP set to None.

What is the difference between ClusterIP and NodePort?

ClusterIP gives a virtual IP reachable only inside the cluster. NodePort adds a port, by default in the 30000-32767 range, on every node so clients outside the cluster can connect through any node IP.

When should I use a headless Service?

Use it when clients need individual pod IPs rather than one virtual IP: StatefulSets that need stable per-pod DNS names, and clients such as gRPC that balance requests themselves.

Why does my ExternalName Service fail with HTTPS?

ExternalName only returns a CNAME. The client still sends the alias name in the Host header and TLS SNI, so the remote server may reject the request or present a certificate for a different name. Call the real hostname or use a selector-less Service.

How do I keep the client source IP in Kubernetes?

Set externalTrafficPolicy to Local on a NodePort or LoadBalancer Service. Traffic then goes only to pods on the receiving node without SNAT, so pods see the real client IP. Spread pods evenly to avoid uneven load.

Is the Endpoints API deprecated?

Yes. The Endpoints API has been deprecated since Kubernetes v1.33. EndpointSlices, stable since v1.21, are the replacement for reading and writing a Service's backends.

Do I need Ingress if I use LoadBalancer Services?

Not for TCP or UDP services. For many HTTP services, a single Gateway API or Ingress controller is cheaper and gives host and path routing, TLS termination and shared policies.

What does trafficDistribution PreferSameZone do?

It asks the Service proxy to prefer endpoints in the same zone as the client and fall back to other zones when none are ready. It reduces latency and cross-zone data charges in multi-zone clusters.

References

Interested in learning more?Get a callback from our training advisors.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Angry Angry 0
Sad Sad 0
Wow Wow 0
Mridul I am a passionate technology enthusiast with a strong focus on DevOps, Cloud Computing, and Cybersecurity. Through my blogs at DevOps Training Institute, I aim to simplify complex concepts and share practical insights for learners and professionals. My goal is to empower readers with knowledge, hands-on tips, and industry best practices to stay ahead in the ever-evolving world of DevOps.