Lesson 8: Service — stable networking for Pods
So far we learned that Kubernetes keeps several copies (Pods) of your app alive and recreates them when they fail. But there is a quiet problem: every Pod has its own network address (IP), and that address is ephemeral — it changes whenever a Pod dies, is recreated, or moves to a different node. If
A Service is like the front desk phone number of an office. The staff keep changing, but whoever calls always dials the same number — and the call reaches whoever is available.
- Service
- A Kubernetes object that gives a group of Pods a stable name and network address and load-balances requests across them. The address stays fixed even as the Pods change.
- ClusterIP
- The default Service type: an internal virtual address reachable only from within the cluster, so internal components can reach it but the outside world cannot.
- Selector & Labels
- A label is a key-value tag attached to a Pod (for example app: web). A Service's selector states which labels to look for, so the Service knows which Pods to send traffic to.
- Ephemeral Pod IP
- Every Pod gets its own IP, but that IP is not stable: it changes when the Pod is recreated or moved to another node. So you must not rely on it directly.
- Load Balancing
- Spreading incoming requests across several identical Pods, so no single copy is overloaded and the service stays available.
- targetPort
- The port the application inside the Pod actually listens on. The Service receives traffic on its port and forwards it to the Pod's targetPort.