Kubernetes4 min read· 3 practice problems

NodePort vs LoadBalancer vs Ingress in Kubernetes: differences, when to use each, and what breaks

NodePort opens a port on every node and LoadBalancer adds a cloud load balancer; both are Service types. Ingress is an L7 rule set that routes HTTP to Services by host and path. Also covers a pending EXTERNAL-IP and node port timeouts.

On this page
  1. Short answer: NodePort and LoadBalancer are Service types; Ingress is HTTP routing in front of them
  2. At a glance
  3. How it actually works
  4. When to use which
  5. Failure 1: EXTERNAL-IP stays <pending>
  6. Failure 2: the node port times out from outside, every LB target unhealthy
  7. Failure 3: the wrong Ingress controller picked it up
  8. What not to do
  9. Summary
  10. Quick diagnostic checklist

Short answer: NodePort and LoadBalancer are Service types; Ingress is HTTP routing in front of them

Service types stack: ClusterIP → NodePort → LoadBalancer. NodePort opens the same port on every node (30000-32767 by default), and LoadBalancer creates a cloud load balancer (LB) that usually forwards to those node ports. Ingress is not a Service type but L7 rules that route to Services by host and path. Its controller usually sits behind one LoadBalancer Service, so you need no LB per service.

At a glance

  • NodePort — one port on every node IP · L4 · clients or an upstream device use node IPs directly · breaks as: firewall timeouts
  • LoadBalancer — an LB with an external IP · L4 · attached per Service by the cloud controller (MetalLB or similar on-prem) · with no implementation: <pending>
  • Ingress — a separate resource · L7, HTTP(S) only · one controller routes to many Services by Host and path · breaks as: 404 or the wrong controller

How it actually works

spec:                     # Service checkout
  type: LoadBalancer      # NodePort: node ports only, no LB
  ports: [{ port: 80, targetPort: 8080 }]
$ kubectl -n shop get svc checkout
NAME       TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
checkout   LoadBalancer   10.96.112.40   203.0.113.50   80:31380/TCP   5m

80:31380 means Service port 80 is open as port 31380 on every node. A request goes LB (203.0.113.50) → port 31380 on any node → kube-proxy rules → a pod. With an Ingress, the only outside IP is the controller Service's EXTERNAL-IP; app Services stay ClusterIP.

The default externalTrafficPolicy: Cluster may send traffic to pods on other nodes, but SNAT hides the client IP from the app. Local uses only pods on the receiving node and keeps the client IP; nodes without a pod fail kube-proxy's healthCheckNodePort and drop out of the LB.

When to use which

  • Called only from inside the cluster → ClusterIP
  • An on-prem L4 device pointing at the nodes, or a quick test → NodePort
  • Non-HTTP TCP or UDP (databases, MQTT) exposed outside → LoadBalancer
  • Many HTTP(S) services split by domain and path, TLS in one place → Ingress

Failure 1: EXTERNAL-IP stays <pending>

NAME       TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
checkout   LoadBalancer   10.96.112.40   <pending>     80:31380/TCP   40m

Completely empty Events in kubectl describe svc mean nothing exists to create the LB (a cloud controller, or MetalLB on-prem), as is common on kubeadm-built clusters. Install an LB implementation or point an upstream device at the node port. A SyncLoadBalancerFailed event's message names the cloud-side cause (permissions, quota, subnets).

Failure 2: the node port times out from outside, every LB target unhealthy

curl -m 3 http://10.0.1.11:31380/healthz      # node in the same VPC: 200
curl -m 3 http://203.0.113.31:31380/healthz   # office PC: times out after 3 s

Inside works, outside times out: a security group or node firewall is blocking, not kube-proxy or the pods (firewalld looks open but connections are blocked). Blocked LB health checks turn every target unhealthy; they come from the LB's addresses, not the client's, so open that range. Under Local, unhealthy pod-less nodes are normal.

Failure 3: the wrong Ingress controller picked it up

With an external and an internal controller, ingressClassName decides which LB serves the Ingress. If a copied manifest keeps the other class, the controller your domain points to lacks the rule and returns 404.

$ kubectl -n shop get ingress portal
NAME     CLASS            HOSTS                ADDRESS     PORTS   AGE
portal   nginx-internal   portal.example.com   10.0.9.15   80      3m
$ dig +short portal.example.com
203.0.113.20

An ADDRESS that differs from the DNS IP means the wrong class; get the right name from kubectl get ingressclass.

What not to do

  • A LoadBalancer for every HTTP service — LBs, public IPs and certificates multiply per service.
  • Opening all of 30000-32767 to 0.0.0.0/0 over a timeout — open only needed sources (LB range, office).

Summary

  1. Draw the way in: DNS → LB → node port → (Ingress controller) → pod
  2. <pending> → start with the describe Events
  3. Timeout only from outside → security groups, firewalls and the health check source
  4. 404 only through the Ingress → compare ADDRESS with the DNS IP, then ingressClassName

Practise this case with Ingress class mismatch sends traffic to the wrong controller.

Quick diagnostic checklist

  • Start with TYPE, EXTERNAL-IP and PORT(S) in kubectl get svc to see how the Service is exposed.
  • If EXTERNAL-IP is <pending>, check whether the Events in kubectl describe svc are empty (no LB implementation).
  • If the Events show SyncLoadBalancerFailed, read the message for permission, quota or subnet errors.
  • Call the same node port from inside and outside the cluster to find where it is blocked.
  • If it times out only from outside, check that cloud security groups and node firewalls allow the node port (30000-32767).
  • If every LB target is unhealthy, check that the health check source (the LB's address range) and port are allowed.
  • With externalTrafficPolicy: Local, nodes without a pod showing unhealthy is expected behavior.
  • If an Ingress returns 404, compare ADDRESS in kubectl get ingress with the domain's DNS IP and check ingressClassName.

Practice with this guide

Reviewed problems about the same failure. Write the cause, recovery, and prevention yourself, then compare with the model answer.

Read next