How to use PodTemplate

1/6/2019

I saw that there is an object named PodTemplate which have little documentation.

It is mentioned:

Pod templates are pod specifications which are included in other objects, such as Replication Controllers, Jobs, and DaemonSets.

But I am not sure how to mention it on Replication Controllers, Jobs or DaemonSets.

I created a PodTemplate like this:

kubectl apply -f - <<EOF
apiVersion: v1
kind: PodTemplate
metadata:
  name: pod-test
  namespace: default
template:
  metadata:
    name: pod-template
  spec:
    containers:
    - name: container
      image: alpine
      command: ["/bin/sh"]
      args: ["-c", "sleep 100"]
EOF

I want to use it in a DaemonSet, how can I do it ?

Here is an example for DaemonSet YAML:

kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: pod-by-daemonset
  namespace: default
spec:
  selector:
    matchLabels:
      name: selector
  template:
    metadata:
      labels:
        name: selector
    spec:
      containers: # I don't want to specify it, I want to use the template.
      - name: container
        image: alpine 

EOF
-- E235
kubernetes
kubernetes-pod

1 Answer

1/6/2019

Interestingly the page for DaemonSet gives an example of creating a DaemonSet and says that

the .spec.template is a pod template. It has exactly the same schema as a Pod, except it is nested and does not have an apiVersion or kind.

So the intention is to inline the Pod schema in the DaemonSet.

However, there does seem to have been a plan to be able to reference a PodTemplate by the form:

TemplateRef:
Name: <templatename>

What seems to have happened from the trail on github is that this way of referencing a predefined PodTemplate was added but not finished and then removed. You can give it a try but it looks to me like only the inline spec is supported.

-- Ryan Dawson
Source: StackOverflow