02. Pods, Services, and Ingress — Objects that move traffic¶
⏱️ Estimated time: 22 min | Level: intermediate
ELI5 callback: Think of a busy shipping port. The dock manager must place every container on the right ship. Heavy ML work needs a cargo crane, and port security keeps lanes and permissions clean.
Pods are the real scheduling unit¶
Kubernetes schedules pods, not naked containers floating by themselves. A pod gives colocated containers one network identity and one lifecycle. Keep the analogy close. The dock manager reads the manifest, the container carries one workload unit, the ship offers capacity, the cargo crane handles ML-heavy lifts, and port security blocks unsafe access. Simple, no? For most apps, one main container per pod stays easiest to reason about. See. The pod is the deployment atom. Now watch.
pod shape
┌────────────┐ ┌────────────┐ ┌────────────┐
│ spec │ -> │ pod │ -> │ ip │
└─────┬──────┘ └─────┬──────┘ └─────┬──────┘
│ │ │
v v v
resources | containers | identity
One pod gets one IP and one fate.
Services give stable networking over changing pods¶
A Service is a stable routing abstraction over a changing backend set. Labels and selectors decide which pods receive that traffic. ClusterIP is the default internal virtual address for east-west calls. The data plane then translates that virtual address into healthy backends. See. Service first, endpoints second. Now watch.
service flow
┌────────────┐ ┌────────────┐ ┌────────────┐
│ client │ -> │ service │ -> │ pods │
└─────┬──────┘ └─────┬──────┘ └─────┬──────┘
│ │ │
v v v
virtual IP | endpoint set | ready targets
Stable name, changing backends.
Ingress adds HTTP entry into the cluster¶
Ingress handles host and path based HTTP routing from outside. The resource alone does nothing until a controller watches it. That controller configures a reverse proxy or cloud load balancer. Host rules, paths, and TLS settings decide how requests enter. See. YAML alone does not route traffic. Now watch.
north-south path
┌────────────┐ ┌────────────┐ ┌────────────┐
│ internet │ -> │ ingress │ -> │ service │
└─────┬──────┘ └─────┬──────┘ └─────┬──────┘
│ │ │
v v v
DNS + TLS | controller | backend pods
The controller makes the resource real.
ClusterIP, NodePort, and LoadBalancer solve different problems¶
ClusterIP stays inside the cluster and is safest by default. NodePort opens the same port on every node in the cluster. LoadBalancer asks the cloud provider to create an external balancer. Exposure choice changes security, cost, and operator pain immediately. See. Pick the smallest exposure that meets the requirement. Now watch.
service types
┌────────────┐ ┌────────────┐ ┌────────────┐
│ clusterip │ -> │ nodeport │ -> │ lb │
└─────┬──────┘ └─────┬──────┘ └─────┬──────┘
│ │ │
v v v
internal only | every node | public front door
More exposure means more blast radius.
Debug traffic with sequence, not panic¶
Most traffic bugs are label mistakes, readiness mistakes, or DNS mistakes. Keep routing layers understandable before adding mesh features on top. Logs, events, endpoints, and ingress status usually reveal the truth. Start from the client and walk one hop at a time. See. Networking needs sequence more than intuition. Now watch.
debug order
┌────────────┐ ┌────────────┐ ┌────────────┐
│ client │ -> │ dns │ -> │ backend │
└─────┬──────┘ └─────┬──────┘ └─────┬──────┘
│ │ │
v v v
name lookup | routing | app response
Check one hop before jumping ahead.
Where this lives in the wild¶
- SaaS control planes expose public APIs through ingress and keep internal workers on ClusterIP.
- E-commerce checkout services use stable service DNS while pods roll underneath.
- Kubeflow dashboards often sit behind ingress controllers with shared TLS policy.
- Platform teams standardize labels so service selectors remain predictable across namespaces.
Pause and recall¶
- Why is a pod more than just one container process?
- Why do Services exist if pods already have IP addresses?
- Why is an Ingress resource useless without a controller?
- When would you choose ClusterIP over NodePort or LoadBalancer?
Interview Q&A¶
Q: Why should clients call a Service name instead of a pod IP? A: Pods are replaced frequently, so their IPs change as health and scheduling change. A Service gives a stable name and backend selection over that churn. Common wrong answer to avoid: “Because Services are faster than pod IPs.”
Q: Why keep one main container per pod for most apps? A: One main process per pod keeps lifecycle, logging, and failure ownership clear. Multiple tightly coupled containers are fine, but they should share a real reason. Common wrong answer to avoid: “Because Kubernetes forbids multiple containers in one pod.”
Q: Why is NodePort rarely the best production entry pattern? A: It opens the same port on every node and pushes more network policy burden onto operators. A managed load balancer or ingress path is usually cleaner and safer. Common wrong answer to avoid: “Because NodePort is deprecated.”
Q: Why do readiness probes matter for Services and Ingress? A: Readiness decides whether a pod should receive live traffic right now. Without it, routing can hit processes that started but are not actually ready. Common wrong answer to avoid: “They are only for dashboards and status pages.”
Apply now (5 min)¶
Draw one web request from internet to pod using four boxes only. Label where DNS, TLS, service selection, and readiness each appear. Now replace pod IPs mentally and confirm the Service still works. Next, choose ClusterIP, NodePort, or LoadBalancer for the entry path. Finally, list the first three objects you would inspect during a 502.
Bridge. Objects defined. But how do we deploy and scale them? → 03 → 03-deployments-and-scaling.md