Skip to main content
RunBook Academy

KubernetesXXXVIII · ServicesServices

Service types — choosing the right exposure for the traffic

Advanced⏱ ~17 minkubectl

What you'll learn

  • Compare the four Service types and their use cases
  • Choose the right Service type for a traffic profile
  • Identify the failure modes of each Service type
  • Apply the operational discipline of preferring internal Services

Prerequisites

Verified against Kubernetes 1.34.x · kubeadm 1.34.x · kubectl 1.34.x · etcd 3.6.x · CoreDNS 1.11.x · containerd 1.7.x / 2.x · 2026-08-16

Not yet marked complete on this device.

Kubernetes exposes four Service types, each with a distinct exposure model. The choice is driven by the traffic profile: internal-only, node-local, cloud- managed, or external alias. This lesson walks the types, the trade-offs, and the operational discipline of choosing the right Service type.

The four Service types

The four Service types are:

TypeUse caseExposure
ClusterIPInternal-onlyCluster-internal virtual IP
NodePortDevelopment, on every nodeA port on every node
LoadBalancerCloud-managed, per-ServiceA cloud load balancer
ExternalNameCNAME aliasA DNS CNAME

A fifth pattern, headless services, is a Service with clusterIP: None; the Service has no ClusterIP and routes directly to the Pod IPs.

ClusterIP

The default Service type. The ClusterIP is a virtual IP that is reachable only from inside the cluster. The ClusterIP is the right choice for service-to-service communication.

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

The ClusterIP is the basis of service discovery. The DNS resolver serves the ClusterIP for the Service’s name.

NodePort

The NodePort Service exposes a port on every node. The port is in the range 30000-32767 by default. The traffic is forwarded to the Service’s ClusterIP, which is forwarded to the Pods.

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

The NodePort is the simplest way to expose a Service externally. The trade-off is that the cluster operator must point external traffic at a specific node’s IP; if the node fails, the traffic is lost.

LoadBalancer

The LoadBalancer Service allocates a cloud-provider load balancer. The load balancer is the external endpoint; the traffic is forwarded to the Service’s ClusterIP, which is forwarded to the Pods.

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

The LoadBalancer is the cloud-managed pattern. The trade-off is the cost (per-Service) and the operational complexity (the cloud provider’s load balancer must be configured).

ExternalName

The ExternalName Service is a CNAME alias to an external DNS name. The Service has no ClusterIP; the DNS resolver returns the CNAME record.

apiVersion: v1
kind: Service
metadata:
  name: external-db
spec:
  type: ExternalName
  externalName: db.example.com

The ExternalName is the right choice for services that live outside the cluster. The DNS resolver returns the CNAME; the client connects to the external service.

Headless services

A headless service is a Service with clusterIP: None. The Service has no ClusterIP; the DNS resolver returns the Pod IPs directly.

apiVersion: v1
kind: Service
metadata:
  name: billing
spec:
  clusterIP: None
  selector:
    app: billing
  ports:
    - port: 80
      targetPort: 8080

The headless service is the right choice for StatefulSets where the client needs to address each Pod directly. The DNS resolver returns the Pod IPs; the client connects to the Pods without going through the kube-proxy.

The exposure matrix

The four Service types expose the Service at different layers:

TypeLayerExternal?
ClusterIPCluster-internalNo
NodePortNodeYes (port on every node)
LoadBalancerCloud load balancerYes (cloud-managed)
ExternalNameDNSYes (DNS alias)
HeadlessCluster-internalNo (no ClusterIP)

The choice matrix

The choice of Service type is driven by the traffic profile:

  • Internal-only service: ClusterIP. The default for service-to-service communication.
  • HTTP traffic from outside: Ingress (a separate object). The Ingress is the production choice for HTTP.
  • Non-HTTP traffic from outside: LoadBalancer. The cloud-managed pattern for TCP/UDP.
  • Development or testing: NodePort. The simplest way to expose a Service externally.
  • External service: ExternalName. The CNAME alias to an external DNS name.
  • Stateful workload: Headless. The DNS resolver returns the Pod IPs directly.

The failure modes

The four Service types’ failure modes:

  • ClusterIP: empty EndpointSlice, selector mismatch, port mismatch.
  • NodePort: node failure, port conflict, no external traffic.
  • LoadBalancer: cloud provider failure, cost optimization, no external traffic.
  • ExternalName: DNS misconfiguration, CNAME chain too long.

The operational discipline

The Service types’ operational discipline:

  • Prefer ClusterIP. Most services are internal; the ClusterIP is the right choice.
  • Use Ingress for HTTP traffic. The Ingress is the production choice for HTTP traffic from outside the cluster.
  • Use LoadBalancer for non-HTTP traffic. The cloud-managed pattern for TCP/UDP.
  • Use NodePort for development only. The NodePort is the simplest pattern but has no HA.
  • Use ExternalName for external services. The CNAME alias is the right choice for external services.
  • Use Headless for StatefulSets. The DNS resolver returns the Pod IPs directly.
  • Document the Service’s exposure. The cluster operator must understand which Services are external.
  • Audit the exposure at every release. A change in the Service type is a security-relevant change.

Quiz

Knowledge check · 4 questions

  1. Q1. Which Service type is the right choice for a StatefulSet where the client needs to address each Pod directly?

  2. Q2. A LoadBalancer Service allocates a cloud-provider load balancer for every Service in the cluster.

  3. Q3. A cluster has 50 LoadBalancer Services. The cloud provider's bill is dominated by the load balancer cost. The cluster operator must reduce the cost. What is the decision?

    The cluster has 50 LoadBalancer Services. The cloud provider's bill is $5,000/month for the load balancers. The cluster operator must reduce the cost. The Services are HTTP traffic only.

  4. Q4. Name two factors that drive the choice of Service type.

Passing score: 75%. Answers are checked in this browser.

Production discipline

  • Choose the right Service type for the traffic profile. The default is ClusterIP for internal services.
  • Prefer ClusterIP for internal services. The ClusterIP is the right choice for service-to-service communication.
  • Use Ingress for HTTP traffic. The Ingress is the production choice for HTTP traffic from outside the cluster.
  • Use LoadBalancer for non-HTTP traffic. The cloud-managed pattern for TCP/UDP.
  • Use NodePort for development only. The NodePort is the simplest pattern but has no HA.
  • Use ExternalName for external services. The CNAME alias is the right choice for external services.
  • Use Headless for StatefulSets. The DNS resolver returns the Pod IPs directly.
  • Document the Service’s exposure. The cluster operator must understand which Services are external.
  • Audit the exposure at every release. A change in the Service type is a security-relevant change.