Kubernetes: shipping a service · core
Deployment, Service and CronJob manifests
A Deployment runs pods, a Service gives them one stable address by matching labels, and a CronJob runs a task on a schedule. Most first bugs are labels and ports that do not match.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- API: a Deployment with replicas, labels (app: orders, component: api), the container with args, a containerPort, readiness and liveness probes, resource requests and a memory limit. A Service selects the pods by label, with port 80 and targetPort set to the port the app listens on.
- Worker: a second Deployment from the same image with component: worker, a different command in args, no Service, its own resources, and a terminationGracePeriodSeconds long enough to finish the current job.
- Nightly report: a CronJob with schedule "0 2 * * *" and timeZone: "Asia/Kolkata". Without timeZone the schedule follows the controller's zone, usually UTC, so 2 am runs at the wrong time.
- Include the Service selector in labels carefully. If the selector says app: cart-api and the pods say app: cart, the Service has no endpoints. kubectl describe svc shows Endpoints: <none>.
- targetPort must match the port the app listens on. The liveness probe port must match as well, or the kubelet restarts the container again and again.
- containerPort is mostly documentation. It does not open, close or map a port. Give ports names (name: http) and refer to the name in Service and probes.
- Selectors in a Deployment are immutable after creation. Use a rolling update (maxSurge, maxUnavailable) for a safe release.
- Check: kubectl get pods, kubectl describe svc, kubectl get endpointslices -l kubernetes.io/service-name=<name>.
The red pen
Common traps: mistake → fix
Mistake: containerPort: 8080 makes the app listen on 8080
Fix: The app decides its port. containerPort is a note.
Mistake: A Service with the right name always works
Fix: It routes by label selector. A wrong label means no endpoints.
Mistake: A cron schedule uses my local time
Fix: It follows the controller's zone, usually UTC, unless you set timeZone.
Easy to hard
Questions interviewers ask, easy to hard
- What is the relationship between a Deployment, a ReplicaSet and a Pod?
- How does a Service find its pods?
- A Service has no endpoints. How do you debug it?
- Why would a CronJob at 2 am run at 7:30 am Indian time?
- Write the manifests for an API, a queue worker and a nightly job from one image.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.