CD5: Kubernetes essentials

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Pods, Deployments and Services

🎯You'll be able to

Describe RouteRani as a Deployment and a Service, apply it with kubectl, and explain how labels connect them.

🏠The everyday picture

A taxi company keeps "5 cars on the airport route" (the plan), whichever drivers are on shift. Passengers call one phone number for the airport route, not a particular driver. The cars carry a sticker saying "airport", and the dispatcher sends calls to any car with that sticker.

📘What it really is


apiVersion: v1 kind: Service metadata: name: routerani-api spec: selector: { app: routerani-api } ports: [{ port: 80, targetPort: 3000 }] ```

📝A worked example

Input (not verified): load the image into kind with kind load docker-image routerani:1.0.3, run kubectl apply -f routerani.yaml (with the database from Lesson 4 also applied), then kubectl get pods -l app=routerani-api and kubectl delete pod <one of them>.

Expected output: two pods Running; after the delete, kubectl get pods shows a new pod with a different name starting within seconds, because the Deployment noticed only one was left. That's the control loop at work.

🌍Where it's used

📝Case scenario

A team's new Service sent no traffic to their pods. kubectl describe svc showed Endpoints: <none>. The Deployment's pods were labelled app: routerani while the Service selected app: routerani-api. Fixing the label made the endpoints appear. Checking endpoints is the first step whenever a Service "doesn't work".

🖱️Try it

If you have a cluster, apply the YAML and run kubectl get endpoints routerani-api. Then change the Service's selector to a wrong label, apply, and check again. Success: the endpoint list empties when labels don't match and fills when they do. If you don't have a cluster, write down which line in each object makes the link.

⚠️Common mistakes

🛠️For your project

Not required in the projects. As a capstone stretch, write k8s/routerani.yaml for RouteRani and mark in your write-up whether you ran it.

✅Quick check

What does a Deployment do that a single pod doesn't?

Show the answer

Keeps the requested number of pods running and replaces them during updates.

How does a Service find its pods?

Show the answer

Its selector matches the pods' labels.

← PreviousWhat an orchestrator does, and when you need one
ProLearners Assist