如何使用 PodTemplate
How to use PodTemplate
我看到有一个名为 PodTemplate
的对象几乎没有 documentation。
提到:
Pod templates are pod specifications which are included in other
objects, such as Replication Controllers, Jobs, and DaemonSets.
但我不确定如何在 Replication Controllers
、Jobs
或 DaemonSets
上提及它。
我创建了一个 PodTemplate
这样的:
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
我想在 DaemonSet
中使用它,我该怎么做?
这是 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
有趣的是 page for DaemonSet 给出了一个创建 DaemonSet 的例子并说
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.
所以目的是在 DaemonSet 中内联 Pod 模式。
但是,seem to have been a plan 能够通过以下形式引用 PodTemplate:
TemplateRef:
Name: <templatename>
什么seems to have happened from the trail on github 是这种引用预定义的PodTemplate 的方式被添加但未完成然后被删除。您可以尝试一下,但在我看来似乎只支持内联规范。
我看到有一个名为 PodTemplate
的对象几乎没有 documentation。
提到:
Pod templates are pod specifications which are included in other objects, such as Replication Controllers, Jobs, and DaemonSets.
但我不确定如何在 Replication Controllers
、Jobs
或 DaemonSets
上提及它。
我创建了一个 PodTemplate
这样的:
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
我想在 DaemonSet
中使用它,我该怎么做?
这是 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
有趣的是 page for DaemonSet 给出了一个创建 DaemonSet 的例子并说
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.
所以目的是在 DaemonSet 中内联 Pod 模式。
但是,seem to have been a plan 能够通过以下形式引用 PodTemplate:
TemplateRef:
Name: <templatename>
什么seems to have happened from the trail on github 是这种引用预定义的PodTemplate 的方式被添加但未完成然后被删除。您可以尝试一下,但在我看来似乎只支持内联规范。