Kubernetes · Chapter 3 of 28
Pods
By the end of this chapter you can write a pod's manifest from nothing, apply it, read every STATUS a pod can show and what each one means, find why a pod crashed from the logs of its last run, run commands inside a container with kubectl exec, and say why Jhatpat never runs a service as a bare pod. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: Meet the cluster
- 4 tasks
- Kubernetes
- In the all labs plan
The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.
Why you need this
The catalog is the service every customer screen calls: 1,240 products for Lucknow, every price, every pack size. Tushar has run it with docker run for two years, and now it has to run on the cluster from a file Ammar can review. Ammar also has a problem waiting: Tushar's rider-ping pod, which checks that riders' phones can reach Jhatpat, says CrashLoopBackOff and nobody knows why.
What you know so far is kubectl run with an image and a port. That cannot say which variables the catalog needs, which command to start, or how many containers belong together, and the dry-run file from chapter 2 is a start you still have to read and change by hand. And when a pod crashes, kubectl get pods only says that it did. You need the manifest's fields, the meaning of each STATUS, and the tools to look inside: the logs of the run that crashed, and a shell in the container.
What you build: 4 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
catalog.yaml: the catalog pod's manifest
Write your first pod manifest by hand, and make the pod from it.
1. Open catalog.yaml. The pod's name and container name are already there.
2. Set the image to jhatpat/catalog:1.2.
3. Add containerPort 8080, and a variable CITY with the value lucknow.
4. Make the pod with kubectl apply -f catalog.yaml.
To pass: a pod named catalog in ch03 has a container named catalog with that image, port and CITY value. It is Running and ready, and it was made by kubectl apply. If a catalog pod with a mistake is already there, delete it, then apply the file again.
- Task 2
rider-ping.yaml: fix the crashing pod
The rider-ping pod in ch03 keeps crashing (CrashLoopBackOff). Find out why and fix it.
1. Read the logs of its last run with kubectl logs and --previous.
2. Fix the mistake in the command in rider-ping.yaml. Keep the rest of the command as it is.
3. Delete the old rider-ping pod.
4. Make it again with kubectl apply -f rider-ping.yaml.
To pass: you ran kubectl logs with --previous. A new rider-ping pod runs busybox:1.37. Its command still prints rider-ping started and then sleeps 3600 seconds. It is Running and ready, with 0 restarts.
- Task 3
exec.txt: inside the notifier pod
Run commands inside the notifier pod, and read two values there.
1. Use kubectl exec on the pod notifier. Print the file /etc/os-release. Find VERSION_ID.
2. Use kubectl exec again. Print the value of the variable NODE_ENV.
3. In exec.txt, below the notes, write each value on a line of its own.
To pass: you ran kubectl exec on notifier, and the command worked. exec.txt has the VERSION_ID value (digits and dots, no quotes) and the NODE_ENV value, each alone on its line. Write only the values, not NAME=value.
- Task 4 · interview question
Interview: why a bare pod is not enough
Ammar will ask: "Why don't we run the catalog as a bare pod in production?"
1. Write two or three sentences in your own words in answer.txt, below the notes.
2. Say what happens to a bare pod when its node fails or someone deletes it.
3. Say what Jhatpat uses instead.
To pass: answer.txt says what happens when the node fails or the pod is deleted, and names the Deployment, its ReplicaSet or its controller.
What you will learn
- A pod manifest: apiVersion, kind, metadata and spec.containers (name, image, ports, command, args, env).
- The STATUS column: Pending, ContainerCreating, Running, Completed, Error, CrashLoopBackOff, ImagePullBackOff, and RESTARTS.
- Logs: -f, --previous, -c, --timestamps.
- kubectl exec: one command in a container, or a shell with -it ... -- sh.
- Two containers in one pod, sharing files.
- restartPolicy and deleting pods: why pods are cattle, not pets.
More in Meet the cluster
Build "Pods" yourself
Jhatpat delivers groceries in ten minutes from 14 dark stores across Lucknow, and its hand-run servers fall over on festival evenings. You move it onto Kubernetes. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.