Kubernetes Service types and Ingress
How does networking work in Kubernetes? Explain Service types (ClusterIP, NodePort, LoadBalancer) and Ingress.
TL;DR
Every Pod gets its own IP, and every Pod can reach every other Pod directly (the CNI plugin, such as Calico or Cilium, implements this). Pod IPs change whenever Pods are replaced, so a Service gives a set of Pods (chosen by a label selector) a stable virtual IP and DNS name and load-balances across the ready ones. ClusterIP (the default) is reachable only inside the cluster. NodePort opens a port on every node. LoadBalancer provisions a cloud load balancer for external traffic. Ingress (or the newer Gateway API) is an L7 router: one entry point that routes HTTP by host and path to many Services, and terminates TLS.
Key points
- Service DNS:
my-svc.my-namespace.svc.cluster.local, or justmy-svcfrom the same namespace. - Only Pods that pass their readiness probe receive Service traffic.
- An Ingress resource does nothing alone: you need an Ingress controller (NGINX, Traefik, or a cloud one). Gateway API is the more expressive successor.
- NetworkPolicies restrict which Pods can talk to which. By default everything is allowed.
- A headless Service (
clusterIP: None) returns the Pod IPs directly; StatefulSets use it.
Debugging "my Pods can't talk":
- Do the Service's selector labels match the Pod labels? (
kubectl get endpoints my-svcshows none if not.) - Is the
targetPortthe port the container really listens on? - Are the Pods Ready?
- Does DNS resolve (
nslookup my-svcfrom a debug Pod)? - Is a NetworkPolicy blocking it?
Example
apiVersion: v1
kind: Service
metadata: { name: api }
spec:
selector: { app: api }
ports: [{ port: 80, targetPort: 8080 }]
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata: { name: web }
spec:
rules:
- host: api.example.com
http:
paths:
- { path: /, pathType: Prefix, backend: { service: { name: api, port: { number: 80 } } } }Common follow-ups
- Why not a LoadBalancer Service for every app? Each one is a separate paid cloud load balancer. One Ingress controller can serve many apps.
- What does kube-proxy do? It programs iptables or IPVS rules on each node so the Service IP forwards to Pod IPs (some CNIs like Cilium replace it with eBPF).
What interviewers look for
Tip
Explain why Services exist (Pod IPs are ephemeral), the three types, Ingress as L7 routing, and a step-by-step debugging checklist.
- Red flag: hard-coding Pod IPs.