What is template field for Kubernetes

5/10/2020

enter image description here

What does the field mean?

Besides, if I will use it, what conditions my configuration need to meet?

-- zhangqichuan
kubernetes

2 Answers

5/11/2020

Template field determines how a pod will be created. In this field you specify metadata and spec values. Pod Template is used in workloads such as DaemonSets, Deployments, Jobs. Based on this template it creates a pod to match desired state.

Metadata field in template section is mostly used to specify labels that will be assigned to each pod created by the controller (Deployment, DaemonSet etc.) and is used for identification. Whenever you specify those labels, you have to also specify selector that matches pod template's labels.

Spec field is a specification of the desired behavior of the pod- configuration settings that will be used by a pod. Every replica of the pod will match this configuration.

Each workload controller react different to changes in pod template. For example, deployment will first create a new pod to match current template and then delete pod that doesn't match the template.

-- KFC_
Source: StackOverflow

5/10/2020

A deployment creates pods. The template is a template for how to create those pods. If you want to use a deployment (where K8s automatically maintains a configured number of replicas of your pod) then you must have a template for creating the pods. Note that the spec part also belongs to the template.

See the docs.

-- ewramner
Source: StackOverflow