liveBook · Manning

Pod template

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

A Pod template is a declarative specification from which Kubernetes creates Pods.

A Pod template is a declarative Pod specification nested inside a Deployment. The Deployment creates Pods from it and keeps the desired number running. section 15.3

Use a template to define how managed Pods are created:

  • Put labels in the template and make the Deployment selector match them, so the controller can find its Pods. section 15.3
  • Place the complete Pod specification under template.spec, including containers and health probes. section 15.3
  • Change replicas or the template with kubectl to scale the application or roll out updated Pods. section 15.3

A template inside a Deployment

In Listing 15.4, spec.template.metadata.labels identifies the Pods, while spec.template.spec defines their containers. Applying the Deployment creates a Pod with the declared configuration. section 15.3

Listing 15.4 Deployment spec that includes the templated Pod spec
apiVersion: v1 
kind: Deployment
metadata:
  name: numbers-api
spec:                   # this is the Deployment spec
  replicas: 1           # the number of Pods to create
  selector:             # selector to find Pods
    matchLabels:
      app: numbers
      component: api
  template:             # this is the template for creating Pods
    metadata:
      labels:           # labels the Deployment selector uses
        app: numbers
        component: api
    spec:               # and this is the Pod spec
      containers:
        - name: api     # full container spec snipped

Inspect the complete Deployment fragment and see exactly where the labels and Pod specification belong. section 15.3

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

How deep it goes
Explains nesting, labels, selectors, scaling, and probes, but stops short of detailed Pod field coverage.
Examples
Uses a numbers-api Deployment, label selectors, replica scaling, container probes, and kubectl commands.
What it assumes
Assumes basic familiarity with Pods and containers while introducing their reuse inside Deployment specifications.
What you can do after
Operate managed Pods by defining a template, applying it with kubectl, scaling replicas, and observing replacements.
How it connects
Connects Deployments, Pods, containers, labels, selectors, Services, scaling, and health probes.

Also explained in

Compare how 3 books explain pod template →

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.