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


