What are the different Service types in Kubernetes?
ClusterIP exposes a Service only inside the cluster, NodePort opens a port on every node, LoadBalancer provisions a cloud load balancer, and ExternalName maps the Service to an external DNS name.
Explain it simply
Think of an office building. ClusterIP is the internal extension number: staff can dial it, outsiders cannot. NodePort is a side door on every floor at the same door number. LoadBalancer is the main reception desk on the public road. ExternalName is a forwarding note saying 'for this, call another company'.
ClusterIP (default) gives a stable virtual IP and DNS name reachable only within the cluster. NodePort opens a port, 30000 to 32767 by default, on every node, and forwards to the Service. LoadBalancer asks the cloud provider (AWS, GCP, Azure) for an external load balancer pointing at the node ports, giving a public address. ExternalName returns a CNAME to an outside host, such as a managed database, with no proxying.
Each type builds on the previous: LoadBalancer includes NodePort, which includes ClusterIP.
Example
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: ClusterIP # NodePort | LoadBalancer | ExternalName
selector:
app: web
ports:
- port: 80
targetPort: 8080What to say in the interview
"ClusterIP is internal only, NodePort exposes a port on each node, LoadBalancer provisions an external cloud load balancer, and ExternalName is a DNS alias to an outside host. Each of the first three builds on the one before."
Common mistakes
- Using NodePort in production when a LoadBalancer or Ingress is more suitable.