Difficulty: Intermediate
What are the different types of Services in Kubernetes, and when would you use ClusterIP, NodePort, LoadBalancer or ExternalName?
A Service gives a changing set of Pods one stable virtual IP and DNS name, and load-balances traffic across the Pods that match its label selector. There are four types: ClusterIP (internal only, the default), NodePort (opens a port on every node), LoadBalancer (provisions a cloud load balancer) and ExternalName (a DNS alias to something outside the cluster).
app: checkout.checkout.payments.svc.cluster.local pointing to the ClusterIP.Because only Ready Pods are in the EndpointSlice, a failing readiness probe automatically removes a Pod from rotation.
| Type | Reachable from | How it works | Typical use |
|---|---|---|---|
| ClusterIP | Inside the cluster only | Virtual IP from the service CIDR | Service-to-service calls, databases |
| NodePort | Node IP + port (30000-32767) | Builds on ClusterIP and opens the port on all nodes | Dev clusters, bare metal, behind your own LB |
| LoadBalancer | The internet or VPC | Builds on NodePort and asks the cloud for an external LB | Exposing one service publicly on EKS/GKE/AKS |
| ExternalName | Inside the cluster | Returns a CNAME, no proxying | Pointing to a managed DB like an RDS hostname |
The types are layered: a LoadBalancer Service also has a NodePort and a ClusterIP (although cloud controllers can skip the NodePort with allocateLoadBalancerNodePorts: false).
clusterIP: None) is not a separate type but a ClusterIP variant that returns Pod IPs directly from DNS, used by StatefulSets.kubectl get endpointslices -l kubernetes.io/service-name=checkout.port is the Service port, targetPort is the container port. Mixing them up is the most common Service bug.externalTrafficPolicy: Local preserves the client source IP but only sends traffic to nodes that run a Pod.apiVersion: v1
kind: Service
metadata:
name: checkout
spec:
type: ClusterIP # default, internal only
selector:
app: checkout # must match Pod labels exactly
ports:
- port: 80 # port clients use on the Service
targetPort: 8080 # port the container listens on
---
apiVersion: v1
kind: Service
metadata:
name: payments-db
spec:
type: ExternalName # DNS CNAME, no proxying
externalName: payments.abc123.ap-south-1.rds.amazonaws.com
Pods call http://checkout and kube-proxy spreads requests over Ready checkout Pods. payments-db resolves to the RDS hostname, so code can use a cluster-local name.
kubectl get svc checkout -o wide
kubectl get endpointslices -l kubernetes.io/service-name=checkout
kubectl get pods -l app=checkout --show-labels
# Test from inside the cluster
kubectl run tmp --rm -it --image=busybox:1.36 -- wget -qO- http://checkout
Empty endpoints usually mean a label mismatch or Pods that are not Ready.
ClusterIP, NodePort, LoadBalancer, ExternalName, EndpointSlice