kubernetes - 如何使用 PodTemplate

标签 kubernetes kubernetes-pod

我看到有一个名为 PodTemplate 的对象,它有很少的 documentation .

提到:

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

但我不确定如何在 Replication ControllersJobsDaemonSets 上提及它。

我像这样创建了一个 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 的方式被添加但未完成然后被删除。您可以尝试一下,但在我看来似乎只支持内联规范。

关于kubernetes - 如何使用 PodTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54060270/

相关文章:

kubernetes - GKE自定义内部服务域

kubernetes - 如何获取pod内kubernetes部署的系统主机名?

go - pods 如何知道其副本数量

spring-boot - 如何从外部对运行在kubernetes pod中的应用程序进行http调用?

kubernetes - kube-apiserver 无法正常工作, "Index with name namespace does not exist"

kubernetes - Kubernetes 是否缓存 docker-registry secret ?

Kubernetes API : Failure 403 pods is forbidden: User "system:serviceaccount:default:journalbeat" cannot list resource "pods" in API group ""

python - 通过 OpenFaaS 在 Kubernetes 中部署 FastAPI 微服务

kubernetes - 命令以退出代码 7 终止

docker - Hostpath 卷未安装在 Windows 的 Docker 桌面上运行的 kubernetes 上