Problem statement
Namespace frontdoor runs catalog-web, two replicas of the catalog front end, each serving on its own container port. Every consumer of it holds a pod IP that somebody copied out of a listing once, and every restart moves that IP to a new address, so each deploy is followed by a round of edits. The same namespace also runs catalog-batch, somebody else's batch tier, which shares the app label with the web pods and listens on nothing at all. Give the web tier one address that does not move.
About this exercise
A pod IP belongs to a pod, and a pod is disposable: replaced on a rollout, on a node drain, on a crash. Anything that stores one is storing a fact with an expiry date.
A Service is the fix. It is an object with an address of its own - a cluster IP, a virtual address that belongs to the Service and lives as long as the Service does. Traffic sent to it is load balanced across a set of backends, and nothing that talks to it ever learns a pod IP.
Three fields decide what a Service does:
- selector - the labels a pod must carry to be a backend. Membership is computed continuously from the live pods, not written down once. This is why the batch tier matters: a selector that names only app matches those pods too, and they answer nothing.
- port - the port the Service itself answers on.
- targetPort - the port on the pod that traffic is forwarded to. These two are independent on purpose: the address a caller uses is decoupled from the port an application happens to bind.
The set of pod addresses currently behind a Service is not something you have to trust blindly - the cluster publishes it as endpoints, one address per selected, ready pod, and you can read it. When pods churn, the endpoint list changes and the cluster IP does not.
Your shell here sits on the cluster's own network, so a cluster IP answers from it exactly as it would from a pod. Cluster DNS is the one thing that does not reach this far: a name like catalog-web.frontdoor.svc.cluster.local resolves inside a pod, not in this shell, so from here a Service is reached at its address. kubectl explain service.spec lists every field.
How this project is graded
The grader reads your Service back off the live cluster and compares every field against the specification below, probes its cluster IP from this same shell and checks what answers, and compares the published endpoints against the pods the cluster reports as ready right now. It then churns the tier: it creates a pod of its own carrying the web labels in frontdoor, checks that the endpoint list picks it up while the cluster IP and the served response stay exactly as they were, and deletes it again. Nothing you created is ever modified, and both grader-owned objects are removed.
What you will build
One Service, in service.yaml, applied to the cluster:
name catalog-web namespace frontdoor type ClusterIP selector app: catalog and tier: web (both, and nothing else) port 80 targetPort 8080
And one recorded value:
answers/cluster-ip.txt the Service's cluster IP, exactly that address and nothing else
Step 1 - one address for the tier
Create the Service so the web tier answers on a single virtual address, on port 80, whichever pods happen to be running behind it.
cluster_ip_service_matches_the_required_spec and virtual_ip_serves_the_web_backend should pass
Step 2 - the right backends, and only those
The published endpoints must be the two ready web pods and nothing else. The batch pod carries the same app label and would answer no request; if it is in the list, some fraction of your traffic disappears into it.
endpoints_list_exactly_the_ready_web_pods should pass
Step 3 - port 80 in front of port 8080
Nothing in these pods listens on 80. The Service answers there anyway and delivers to the port the container actually binds.
target_port_routes_the_service_port_to_the_container_port should pass
Step 4 - survive the churn
Record the cluster IP in answers/cluster-ip.txt, then restart the web pods and watch what happens: the endpoint list is rewritten with new pod addresses, and the address you wrote down keeps serving. If the recorded value no longer matches the live Service, the address moved - which is what happens when a Service is deleted and recreated rather than left alone.
endpoints_follow_pod_churn_while_the_cluster_ip_holds and recorded_cluster_ip_matches_the_service_after_the_churn should pass
When every test passes
You have:
- One address for the catalog tier that outlives every pod behind it
- A backend set computed from labels, with the batch tier correctly excluded
- A published port that has nothing to do with the port the application binds
- Endpoints you can read, so "which pods am I actually talking to" is a question with an answer
You do not have yet:
- Any control over when a pod joins that list. Right now a pod is a backend the moment it is running, warm or not. That is the next exercise.
Verify
Click Test after every step.
