liveBook · Manning

Pod

As explained in Learn Docker in a Month of Lunches, Second Edition

A Pod is the smallest deployable unit in Kubernetes and encapsulates one or more containers sharing network and storage resources.

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

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Works through Pod YAML, container restarts, inspection, traffic routing, scaling, and configuration; does not detail Kubernetes scheduling internals.
Examples
Uses a pi-printing Pod, a random-number HTTP API, and a logging-configuration lab for a to-do application.
What it assumes
Builds on Docker containers and images while introducing the Kubernetes Pod resource through minimal YAML and runnable commands.
What you can do after
Operate/configure it with kubectl to deploy and inspect Pods, test an HTTP endpoint, scale a Deployment, and check injected configuration.
How it connects
Connects Pods to containers, labels, Services, Deployments, health probes, and ConfigMaps.

Also explained in

Compare how 15 books explain pod →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.