In Kubernetes, you deploy containers inside a Pod rather than modeling containers directly. A Pod wraps one or more containers and watches them: if a container exits, the Pod starts a replacement. A basic Pod specification names the Pod and lists each container’s name and image. Kubernetes assigns the Pod to a node, where the image is pulled and the container starts. section 15.2
Listing 15.1 A basic Pod spec
apiVersion: v1
kind: Pod
metadata:
name: pi
spec:
containers:
- name: pi
image: kiamol/ch05-pi
A minimal Pod YAML for an application that prints pi. The `apiVersion`, `kind`, `metadata`, and `spec` fields identify the resource and its requested configuration. section 15.2
Try the example with `kubectl apply -f ch15/exercises/pi/pod.yaml`, then run `kubectl get pods` and `kubectl logs pi`. Because this application prints a value and exits, watching it with `kubectl get pods --watch` makes the restart behavior visible. Pods are a better fit for components intended to keep running, such as a web app or queue processor. section 15.2
For an HTTP application, the Pod is only one part of the setup:
- Add labels and a named container port to the Pod. Use `kubectl get pods --show-labels` and `kubectl describe pod numbers-api` to inspect it; `kubectl port-forward pod/numbers-api 8015:80` lets you test it locally. section 15.2
- Create a Service whose selector matches the Pod labels to route traffic to it. A Deployment uses a Pod template and label selector to create and manage the desired number of Pods; if one goes missing, it creates another. Scale it with `kubectl scale deploy/numbers-api --replicas 3`. section 15.2 section 15.3
- Reference a ConfigMap from a Pod’s container specification to supply environment variables or mount configuration as files. Check the result with `kubectl exec` against the Pod or its Deployment. section 15.4
Practice: change a running app’s logging configuration
Deploy the to-do app from `ch15/exercises/todo-list`. Its web component normally logs only errors. Inject the lab’s `logging.json` into the web container alongside `config.json`, then check whether existing Pods pick up the change or whether the Deployment must create new ones. section 15.6














